({
id,
projectId,
name,
type,
properties,
}: EditGroupProps)
| 26 | >; |
| 27 | |
| 28 | export default function EditGroup({ |
| 29 | id, |
| 30 | projectId, |
| 31 | name, |
| 32 | type, |
| 33 | properties, |
| 34 | }: EditGroupProps) { |
| 35 | const queryClient = useQueryClient(); |
| 36 | const trpc = useTRPC(); |
| 37 | |
| 38 | const { register, handleSubmit, control, formState } = useForm<IForm>({ |
| 39 | resolver: zodResolver(zForm), |
| 40 | defaultValues: { |
| 41 | type, |
| 42 | name, |
| 43 | properties: Object.entries(properties as Record<string, string>).map( |
| 44 | ([key, value]) => ({ |
| 45 | key, |
| 46 | value: String(value), |
| 47 | }) |
| 48 | ), |
| 49 | }, |
| 50 | }); |
| 51 | |
| 52 | const { fields, append, remove } = useFieldArray({ |
| 53 | control, |
| 54 | name: 'properties', |
| 55 | }); |
| 56 | |
| 57 | const mutation = useMutation( |
| 58 | trpc.group.update.mutationOptions({ |
| 59 | onSuccess() { |
| 60 | queryClient.invalidateQueries(trpc.group.list.pathFilter()); |
| 61 | queryClient.invalidateQueries(trpc.group.byId.pathFilter()); |
| 62 | queryClient.invalidateQueries(trpc.group.types.pathFilter()); |
| 63 | toast('Success', { description: 'Group updated.' }); |
| 64 | popModal(); |
| 65 | }, |
| 66 | onError: handleError, |
| 67 | }) |
| 68 | ); |
| 69 | |
| 70 | return ( |
| 71 | <ModalContent> |
| 72 | <ModalHeader title="Edit group" /> |
| 73 | <form |
| 74 | className="flex flex-col gap-4" |
| 75 | onSubmit={handleSubmit(({ properties: formProps, ...values }) => { |
| 76 | const props = Object.fromEntries( |
| 77 | formProps |
| 78 | .filter((p) => p.key.trim() !== '') |
| 79 | .map((p) => [p.key.trim(), String(p.value)]) |
| 80 | ); |
| 81 | mutation.mutate({ id, projectId, ...values, properties: props }); |
| 82 | })} |
| 83 | > |
| 84 | <InputWithLabel |
| 85 | label="Name" |
nothing calls this directly
no test coverage detected