import { Accordion, Alert, Button, Checkbox, Col, Grid, MultiSelect, NumberInput, PasswordInput, Select, Stack, Text, Textarea, TextInput, Title, } from "@mantine/core"; import { useForm, yupResolver } from "@mantine/form"; import { useModals } from "@mantine/modals"; import { ModalsContextProps } from "@mantine/modals/lib/context"; import { useState } from "react"; import { TbAlertCircle } from "react-icons/tb"; import * as yup from "yup"; import shareService from "../../../services/share.service"; import { CreateShare } from "../../../types/share.type"; import { getExpirationPreview } from "../../../utils/date.util"; const showCreateUploadModal = ( modals: ModalsContextProps, options: { isUserSignedIn: boolean; isReverseShare: boolean; appUrl: string; allowUnauthenticatedShares: boolean; enableEmailRecepients: boolean; }, uploadCallback: (createShare: CreateShare) => void ) => { return modals.openModal({ title: "Share", children: ( ), }); }; const CreateUploadModalBody = ({ uploadCallback, options, }: { uploadCallback: (createShare: CreateShare) => void; options: { isUserSignedIn: boolean; isReverseShare: boolean; appUrl: string; allowUnauthenticatedShares: boolean; enableEmailRecepients: boolean; }; }) => { const modals = useModals(); const generatedLink = Buffer.from(Math.random().toString(), "utf8") .toString("base64") .substr(10, 7); const [showNotSignedInAlert, setShowNotSignedInAlert] = useState(true); const validationSchema = yup.object().shape({ link: yup .string() .required() .min(3) .max(50) .matches(new RegExp("^[a-zA-Z0-9_-]*$"), { message: "Can only contain letters, numbers, underscores and hyphens", }), password: yup.string().min(3).max(30), maxViews: yup.number().min(1), }); const form = useForm({ initialValues: { link: generatedLink, recipients: [] as string[], password: undefined, maxViews: undefined, description: undefined, expiration_num: 1, expiration_unit: "-days", never_expires: false, }, validate: yupResolver(validationSchema), }); return ( <> {showNotSignedInAlert && !options.isUserSignedIn && ( setShowNotSignedInAlert(false)} icon={} title="You're not signed in" color="yellow" > You will be unable to delete your share manually and view the visitor count. )}
{ if (!(await shareService.isShareIdAvailable(values.link))) { form.setFieldError("link", "This link is already in use"); } else { const expiration = form.values.never_expires ? "never" : form.values.expiration_num + form.values.expiration_unit; uploadCallback({ id: values.link, expiration: expiration, recipients: values.recipients, description: values.description, security: { password: values.password, maxViews: values.maxViews, }, }); modals.closeAll(); } })} > ({ color: theme.colors.gray[6], })} > {options.appUrl}/share/ {form.values.link == "" ? "myAwesomeShare" : form.values.link} {!options.isReverseShare && ( <>