({ datetime }: AddReferenceProps = {})
| 23 | } |
| 24 | |
| 25 | export default function AddReference({ datetime }: AddReferenceProps = {}) { |
| 26 | const { projectId } = useAppParams(); |
| 27 | const queryClient = useQueryClient(); |
| 28 | const { register, handleSubmit, formState, control } = useForm<IForm>({ |
| 29 | resolver: zodResolver(zCreateReference), |
| 30 | defaultValues: { |
| 31 | title: '', |
| 32 | description: '', |
| 33 | projectId, |
| 34 | datetime: datetime || new Date().toISOString(), |
| 35 | }, |
| 36 | }); |
| 37 | |
| 38 | const trpc = useTRPC(); |
| 39 | const mutation = useMutation( |
| 40 | trpc.reference.create.mutationOptions({ |
| 41 | onSuccess() { |
| 42 | queryClient.invalidateQueries(trpc.reference.pathFilter()); |
| 43 | toast('Success', { |
| 44 | description: 'Reference created.', |
| 45 | }); |
| 46 | popModal(); |
| 47 | }, |
| 48 | onError: handleError, |
| 49 | }), |
| 50 | ); |
| 51 | |
| 52 | return ( |
| 53 | <ModalContent> |
| 54 | <ModalHeader title="Add reference" /> |
| 55 | <form |
| 56 | className="flex flex-col gap-4" |
| 57 | onSubmit={handleSubmit((values) => mutation.mutate(values))} |
| 58 | > |
| 59 | <InputWithLabel label="Title" {...register('title')} autoFocus /> |
| 60 | <InputWithLabel label="Description" {...register('description')} /> |
| 61 | <Controller |
| 62 | control={control} |
| 63 | name="datetime" |
| 64 | render={({ field }) => ( |
| 65 | <InputDateTime {...field} label="Date and time" /> |
| 66 | )} |
| 67 | /> |
| 68 | <ButtonContainer> |
| 69 | <Button type="button" variant="outline" onClick={() => popModal()}> |
| 70 | Cancel |
| 71 | </Button> |
| 72 | <Button type="submit" disabled={!formState.isDirty}> |
| 73 | Create |
| 74 | </Button> |
| 75 | </ButtonContainer> |
| 76 | </form> |
| 77 | </ModalContent> |
| 78 | ); |
| 79 | } |
nothing calls this directly
no test coverage detected