| 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 type { projectsService |
| 11 | import { Button } |
| 12 | import { |
| 13 | Card, |
| 14 | CardContent, |
| 15 | CardDescription, |
| 16 | CardFooter, |
| 17 | CardHeader, |
| 18 | CardTitle, |
| 19 | } from '@/components/ui/card' |
| 20 | import { Checkbox } |
| 21 | import { |
| 22 | Field, |
| 23 | FieldDescription, |
| 24 | FieldGroup, |
| 25 | FieldLabel, |
| 26 | } from '@/components/ui/field' |
| 27 | import { updateClientInvolvementLevelAction } |
| 28 | import { |
| 29 | clientInvolvementEntities, |
| 30 | clientInvolvementEntityLabels, |
| 31 | clientInvolvementProjectSchema, |
| 32 | defaultClientInvolvement, |
| 33 | } from '../common' |
| 34 | |
| 35 | type FormValues |
| 36 | |
| 37 | export function ClientApprovalCard({ |
| 38 | projectId, |
| 39 | organizationId, |
| 40 | settings, |
| 41 | }: { |
| 42 | projectId: string |
| 43 | organizationId: string |
| 44 | settings: Awaited |
| 45 | }) { |
| 46 | const router = |
| 47 | |
| 48 | const form = |
| 49 | resolver: zodResolver(clientInvolvementProjectSchema |
| 50 | defaultValues: { |
| 51 | clientInvolvement: settings.clientInvolvement |
| 52 | projectId, |
| 53 | organizationId, |
| 54 | }, |
| 55 | }) |
| 56 | |
| 57 | const { execute, |
| 58 | onSuccess() { |
| 59 | router.refresh() |
| 60 | toast.success('Updated client involvement level |
| 61 | }, |
| 62 | onError({ error |
| 63 | toast.error( |
| 64 | error.serverError ?? |
| 65 | ) |
| 66 | }, |
| 67 | }) |
| 68 | |
| 69 | return ( |
| 70 | <Card> |
| 71 | <CardHeader> |
| 72 | <CardTitle>Client Approval</CardTitle |
| 73 | <CardDescription> |
| 74 | Choose which parts of the workflow require client approval. Turn off |
| 75 | the ones your client isn't involved in — those steps will be handled |
| 76 | internally instead. |
| 77 | </CardDescription> |
| 78 | </CardHeader> |
| 79 | <form onSubmit={form |
| 80 | <CardContent> |
| 81 | <FieldGroup> |
| 82 | {clientInvolvementEntities.map(( |
| 83 | <Controller |
| 84 | control={form.control |
| 85 | key={entity} |
| 86 | name={`clientInvolvement.${entity |
| 87 | render={({ field |
| 88 | <Field orientation=' |
| 89 | <Checkbox |
| 90 | checked={field.value |
| 91 | id={`client-involvement-${entity |
| 92 | onCheckedChange={(checked) |
| 93 | field.onChange(checked |
| 94 | } |
| 95 | /> |
| 96 | <div className='flex flex-col gap-0.5 |
| 97 | <FieldLabel htmlFor={ |
| 98 | {clientInvolvementEntityLabels[entity]. |
| 99 | </FieldLabel> |
| 100 | <FieldDescription> |
| 101 | {clientInvolvementEntityLabels[entity]. |
| 102 | </FieldDescription> |
| 103 | </div> |
| 104 | </Field> |
| 105 | )} |
| 106 | /> |
| 107 | ))} |
| 108 | </FieldGroup> |
| 109 | </CardContent> |
| 110 | <CardFooter> |
| 111 | <Button |
| 112 | className='mt-4' |
| 113 | disabled={!form. |
| 114 | loading={isPending} |
| 115 | type='submit' |
| 116 | > |
| 117 | <Save className=' |
| 118 | Save Approval Settings |
| 119 | </Button> |
| 120 | </CardFooter> |
| 121 | </form> |
| 122 | </Card> |
| 123 | ) |
| 124 | } |