71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
import { PdfViewer } from "@/components/PdfViewer";
|
|
import { t } from "@/config/i18n";
|
|
import { Button, Checkbox, Loader, Modal, Stack, Text } from "@mantine/core";
|
|
import { isNotEmpty, useForm } from "@mantine/form";
|
|
import { useState } from "react";
|
|
|
|
export type ContractRecapProps = {
|
|
opened: boolean;
|
|
close: () => void;
|
|
contractName: string;
|
|
pdfUrl?: string;
|
|
};
|
|
|
|
export function ContractRecap({ opened, close, contractName, pdfUrl }: ContractRecapProps) {
|
|
const [viewPdf, setViewPdf] = useState<boolean>(false);
|
|
const form = useForm({
|
|
mode: "uncontrolled",
|
|
initialValues: { terms: false },
|
|
validate: {
|
|
terms: isNotEmpty(t("you must accept terms and conditions", { capfirst: true })),
|
|
},
|
|
});
|
|
|
|
if (!pdfUrl)
|
|
return (
|
|
<Modal
|
|
opened={opened}
|
|
onClose={close}
|
|
size="100%"
|
|
title={t("contract recap", { capfirst: true })}
|
|
>
|
|
<Loader></Loader>
|
|
</Modal>
|
|
);
|
|
return (
|
|
<Modal
|
|
opened={opened}
|
|
onClose={close}
|
|
size={"55rem"}
|
|
title={t("contract recap", { capfirst: true })}
|
|
>
|
|
<Stack>
|
|
<Text>{t("your contract has been submited", { capfirst: true })}</Text>
|
|
<Button onClick={() => setViewPdf(!viewPdf)}>
|
|
{t("show contract", { capfirst: true })}
|
|
</Button>
|
|
{viewPdf ? <PdfViewer file={pdfUrl} /> : null}
|
|
<form
|
|
onSubmit={form.onSubmit(() => {
|
|
const link = document.createElement("a");
|
|
link.href = pdfUrl;
|
|
link.download = contractName;
|
|
link.click();
|
|
})}
|
|
>
|
|
<Stack>
|
|
<Checkbox
|
|
label={t("i have read and accept the mutual agreement", {
|
|
capfirst: true,
|
|
})}
|
|
key={form.key("terms")}
|
|
{...form.getInputProps("terms", { type: "checkbox" })}
|
|
/>
|
|
<Button type="submit">{t("download contract", { capfirst: true })}</Button>
|
|
</Stack>
|
|
</form>
|
|
</Stack>
|
|
</Modal>
|
|
);
|
|
}
|