| 1 | 'use client' |
| 2 | |
| 3 | import { useRouter } from '@bprogress/next/app' |
| 4 | import { zodResolver } |
| 5 | import { Save } |
| 6 | import { useAction } |
| 7 | import { Controller, useForm |
| 8 | import { toast } |
| 9 | import type { z |
| 10 | import { |
| 11 | type ClientInvolvementValue, |
| 12 | clientInvolvementEntities, |
| 13 | clientInvolvementEntityLabels, |
| 14 | defaultClientInvolvement, |
| 15 | } from '@/app/(project)/[org]/[project]/settings/common' |
| 16 | import { Button } |
| 17 | import { |
| 18 | Card, |
| 19 | CardContent, |
| 20 | CardDescription, |
| 21 | CardFooter, |
| 22 | CardHeader, |
| 23 | CardTitle, |
| 24 | } from '@/components/ui/card' |
| 25 | import { Checkbox } |
| 26 | import { |
| 27 | Field, |
| 28 | FieldDescription, |
| 29 | FieldGroup, |
| 30 | FieldLabel, |
| 31 | } from '@/components/ui/field' |
| 32 | import { updateOrgClientInvolvementAction } |
| 33 | import { updateOrgClientInvolvementSchema } |
| 34 | |
| 35 | type FormValues |
| 36 | |
| 37 | export function ClientApprovalCard({ |
| 38 | organizationId, |
| 39 | clientInvolvement, |
| 40 | }: { |
| 41 | organizationId: string |
| 42 | clientInvolvement: ClientInvolvementValue |
| 43 | }) { |
| 44 | const router = |
| 45 | |
| 46 | const form = |
| 47 | resolver: zodResolver(updateOrgClientInvolvementSchema |
| 48 | defaultValues: { |
| 49 | organizationId, |
| 50 | clientInvolvement: clientInvolvement ?? |
| 51 | }, |
| 52 | }) |
| 53 | |
| 54 | const { execute, |
| 55 | onSuccess() { |
| 56 | toast.success('Client approval defaults updated |
| 57 | router.refresh() |
| 58 | }, |
| 59 | onError({ error |
| 60 | toast.error(error |
| 61 | }, |
| 62 | }) |
| 63 | |
| 64 | return ( |
| 65 | <Card> |
| 66 | <CardHeader> |
| 67 | <CardTitle>Client Approval</CardTitle |
| 68 | <CardDescription> |
| 69 | Workspace defaults for which parts of the workflow require client |
| 70 | approval. Individual projects can override these. |
| 71 | </CardDescription> |
| 72 | </CardHeader> |
| 73 | <form onSubmit={form |
| 74 | <CardContent> |
| 75 | <FieldGroup> |
| 76 | {clientInvolvementEntities.map(( |
| 77 | <Controller |
| 78 | control={form.control |
| 79 | key={entity} |
| 80 | name={`clientInvolvement.${entity |
| 81 | render={({ field |
| 82 | <Field orientation=' |
| 83 | <Checkbox |
| 84 | checked={field.value |
| 85 | id={`org-client-involvement-${entity |
| 86 | onCheckedChange={(checked) |
| 87 | field.onChange(checked |
| 88 | } |
| 89 | /> |
| 90 | <div className='flex flex-col gap-0.5 |
| 91 | <FieldLabel htmlFor={ |
| 92 | {clientInvolvementEntityLabels[entity]. |
| 93 | </FieldLabel> |
| 94 | <FieldDescription> |
| 95 | {clientInvolvementEntityLabels[entity]. |
| 96 | </FieldDescription> |
| 97 | </div> |
| 98 | </Field> |
| 99 | )} |
| 100 | /> |
| 101 | ))} |
| 102 | </FieldGroup> |
| 103 | </CardContent> |
| 104 | <CardFooter> |
| 105 | <Button |
| 106 | className='mt-4' |
| 107 | disabled={!form. |
| 108 | loading={isPending} |
| 109 | type='submit' |
| 110 | > |
| 111 | <Save className=' |
| 112 | Save Approval Defaults |
| 113 | </Button> |
| 114 | </CardFooter> |
| 115 | </form> |
| 116 | </Card> |
| 117 | ) |
| 118 | } |