metis-desk/modules/companies/src/web/folders/folder-quick-editor.tsx

67 lines
1.7 KiB
TypeScript
Raw Normal View History

import { FormDialog } from "@repo/shadcn-ui/components/form-dialog";
import { useTranslation } from "react-i18next";
import type { AccessResponseDTO, CompanyDTO, WorkProfileDTO } from "../../common";
import { AccessForm } from "../access/access-form";
import { WorkProfileForm } from "../profiles/work-profile-form";
export function FolderQuickEditor({
kind,
company,
csrfToken,
data,
profile,
onClose,
onCreated,
}: {
kind: "profile" | "need";
company: CompanyDTO;
csrfToken: string;
data: AccessResponseDTO | undefined;
profile: WorkProfileDTO | undefined;
onClose: () => void;
onCreated: (field: "profileId" | "needId", id: string) => void;
}) {
const { t } = useTranslation("companies");
return (
<FormDialog
cancelLabel={t("cancel")}
formActions
onOpenChange={(open) => {
if (!open) {
onClose();
}
}}
open
title={t(kind === "profile" ? "profiles.new" : "folders.newNeed")}
wide
>
{kind === "profile" && (
<WorkProfileForm
allowQuickCreate={false}
company={company}
csrfToken={csrfToken}
onSaved={(id) => onCreated("profileId", id)}
/>
)}
{kind === "need" && data && profile && (
<AccessForm
allowQuickCreate={false}
csrfToken={csrfToken}
data={data}
initialValues={{ personId: profile.values.personId }}
kind="need"
lockedFields={["personId"]}
onSaved={(id) => {
if (id) {
onCreated("needId", id);
}
}}
people={company.people}
scope={company.id}
/>
)}
</FormDialog>
);
}