import type { ReactView } from "@ethicdevs/react-monolith";
import React from "react";
import type { Organization, ResourceVisibility } from "@prisma/client";
import type { CommonProps, RepositoryWithForkedFromRepo } from "../../types";
import { AppRoute } from "../../routes.defs";
import { IslandWrapper, Layout, PageWrapper } from "../../components";
import { buildRouteLink } from "../../utils/shared";
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}
showForkButton={false}
/>
</IslandWrapper>
<div style={{ height: 32 }} />
{errorMessage && (
<div className={"error_message"}>
<p>{errorMessage}</p>
</div>
)}
<form
method={"POST"}
action={buildRouteLink(AppRoute.REPOSITORY_FORK_ACTION, {
orgSlug: sourceParentOrg.slug,
repoSlug: sourceRepo.slug,
})}
>
<div data-islandid={`${RepositoryForkForm.name}$$0`}>
<RepositoryForkForm
themeScheme={commonProps.themeScheme}
availableParentOrgs={availableParentOrgs}
initialValues={initialValues}
/>
</div>
</form>
</PageWrapper>
</Layout>
);
};
RepositoryForkView.displayName = "RepositoryForkView";
export default RepositoryForkView;