import { Accordion, Alert, Button, Checkbox, Col, Grid, Group, MultiSelect, NumberInput, PasswordInput, Select, Stack, Text, TextInput, Title, } from "@mantine/core"; import { useForm, yupResolver } from "@mantine/form"; import { useModals } from "@mantine/modals"; import { ModalsContextProps } from "@mantine/modals/lib/context"; import getConfig from "next/config"; import { useState } from "react"; import { TbAlertCircle } from "react-icons/tb"; import * as yup from "yup"; import shareService from "../../../services/share.service"; import { ShareSecurity } from "../../../types/share.type"; import ExpirationPreview from "../ExpirationPreview"; const { publicRuntimeConfig } = getConfig(); const showCreateUploadModal = ( modals: ModalsContextProps, isSignedIn: boolean, uploadCallback: ( id: string, expiration: string, recipients: string[], security: ShareSecurity ) => void ) => { return modals.openModal({ title: Share, children: ( ), }); }; const CreateUploadModalBody = ({ uploadCallback, isSignedIn, }: { uploadCallback: ( id: string, expiration: string, recipients: string[], security: ShareSecurity ) => void; isSignedIn: boolean; }) => { const modals = useModals(); const [showNotSignedInAlert, setShowNotSignedInAlert] = useState( publicRuntimeConfig.ALLOW_UNAUTHENTICATED_SHARES == "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: "", recipients: [] as string[], password: undefined, maxViews: undefined, expiration_num: 1, expiration_unit: "-days", never_expires: false, }, validate: yupResolver(validationSchema), }); return ( {showNotSignedInAlert && !isSignedIn && ( 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(values.link, expiration, values.recipients, { password: values.password, maxViews: values.maxViews, }); modals.closeAll(); } })} > ({ color: theme.colors.gray[6], })} > {window.location.origin}/share/ {form.values.link == "" ? "myAwesomeShare" : form.values.link}