GitFOSS
.ts
TypeScript
(application/typescript)
// 1st-party
import type { ReactView } from "@ethicdevs/react-monolith";
// 3rd-party
import React from "react";
// generated via script[generate:prisma]
import { Organization, ResourceVisibility } from "@prisma/client";
// app
import type { CommonProps, RepositoryWithForkedFromRepo } from "../../types";
import { IslandWrapper, Layout, PageWrapper } from "../../components";
// app islands
import RepositoryForkForm from "../../islands/RepositoryForkForm";
import RepositoryHero from "../../islands/RepositoryHero";

export interface RepositoryForkViewProps extends CommonProps {
  availableParentOrgs: Organization[];
  sourceParentOrg: Organization;
  sourceRepo: RepositoryWithForkedFromRepo;
  errorMessage?: null | string;
  initialValues?: {
    target_org_slug: string;
    target_repo_display_name: string;
    target_repo_slug: string;
    target_repo_visibility: ResourceVisibility;
  };
}

const RepositoryForkView: ReactView<RepositoryForkViewProps> = ({
  availableParentOrgs,
  commonProps,
  sourceParentOrg,
  sourceRepo,
  errorMessage = undefined,
  initialValues = undefined,
}) => {
  return (
    <Layout {...commonProps}>
      <PageWrapper>
        <IslandWrapper data-islandid={`${RepositoryHero.name}$$0`}>
          <RepositoryHero
            forkedFromRepo={sourceRepo.forkedFromRepo}
            forksCount={sourceRepo.forks.length}
            path={`Fork`}
            parentOrg={sourceParentOrg}
            repo={sourceRepo}
          />
        </IslandWrapper>
        <div style={{ height: 32 }} />
        {errorMessage && (
          <div className={"error_message"}>
            <p>{errorMessage}</p>
          </div>
        )}
        <form
          action={`/${sourceParentOrg.slug}/${sourceRepo.slug}/fork`}
          method={"POST"}
        >
          <div data-islandid={`${RepositoryForkForm.name}$$0`}>
            <RepositoryForkForm
              availableParentOrgs={availableParentOrgs}
              initialValues={initialValues}
            />
          </div>
        </form>
      </PageWrapper>
    </Layout>
  );
};

RepositoryForkView.displayName = "RepositoryForkView";
export default RepositoryForkView;