diff --git a/apps/backend/src/defaults/carers/carer.dto.ts b/apps/backend/src/defaults/carers/carer.dto.ts index 53c3c31c..47bc0058 100644 --- a/apps/backend/src/defaults/carers/carer.dto.ts +++ b/apps/backend/src/defaults/carers/carer.dto.ts @@ -22,4 +22,4 @@ export class CarerResponseDto extends CarerDto {} export class CarerCreationDto extends OmitType(CarerDto, ["id", "entries", "participant"]) { participant?: number; } -export class CarerMutationDto extends PartialType(OmitType(CarerDto, ["entries"])) {} +export class CarerMutationDto extends PartialType(CarerCreationDto) {} diff --git a/apps/frontend/src/api.gen.ts b/apps/frontend/src/api.gen.ts index 626b38bf..605ad23e 100644 --- a/apps/frontend/src/api.gen.ts +++ b/apps/frontend/src/api.gen.ts @@ -555,17 +555,12 @@ export interface components { entries: number[]; }; CarerMutationDto: { - /** - * @description The id of the carer - * @example 1 - */ - id?: number; /** * @description The name of the carer * @example Grandmother */ name?: string; - participant?: components["schemas"]["ParticipantDto"]; + participant?: number; }; LanguageCreationDto: { /** diff --git a/apps/frontend/src/routes/_auth/administration/carers/edit.$id.tsx b/apps/frontend/src/routes/_auth/administration/carers/edit.$id.tsx index 6b1ecf1a..a1799e92 100644 --- a/apps/frontend/src/routes/_auth/administration/carers/edit.$id.tsx +++ b/apps/frontend/src/routes/_auth/administration/carers/edit.$id.tsx @@ -1,7 +1,7 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { components } from "../../../../api.gen"; import { $api } from "../../../../stores/api"; -import { useQueryClient, useSuspenseQuery } from "@tanstack/react-query"; +import { useQueryClient } from "@tanstack/react-query"; import { Button, TextInput, useForm } from "@quassel/ui"; import { useEffect } from "react"; @@ -10,7 +10,7 @@ type FormValues = components["schemas"]["CarerMutationDto"]; function AdministrationCarersEdit() { const p = Route.useParams(); const q = useQueryClient(); - const carer = useSuspenseQuery($api.queryOptions("get", "/carers/{id}", { params: { path: { id: p.id } } })); + const { data, isSuccess } = $api.useSuspenseQuery("get", "/carers/{id}", { params: { path: { id: p.id } } }); const n = useNavigate(); const editCarerMutation = $api.useMutation("patch", "/carers/{id}", { onSuccess: () => { @@ -35,9 +35,9 @@ function AdministrationCarersEdit() { }; useEffect(() => { - f.setValues(carer.data ?? {}); + f.setValues({ ...data, participant: data.participant?.id }); f.resetDirty(); - }, [carer.isSuccess, carer.data]); + }, [isSuccess, data]); return ( <> diff --git a/apps/frontend/src/routes/_auth/administration/languages/edit.$id.tsx b/apps/frontend/src/routes/_auth/administration/languages/edit.$id.tsx index 841e2f6c..eb46fd9c 100644 --- a/apps/frontend/src/routes/_auth/administration/languages/edit.$id.tsx +++ b/apps/frontend/src/routes/_auth/administration/languages/edit.$id.tsx @@ -1,7 +1,7 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { components } from "../../../../api.gen"; import { $api } from "../../../../stores/api"; -import { useQueryClient, useSuspenseQuery } from "@tanstack/react-query"; +import { useQueryClient } from "@tanstack/react-query"; import { Button, TextInput, useForm } from "@quassel/ui"; import { useEffect } from "react"; @@ -10,11 +10,10 @@ type FormValues = components["schemas"]["LanguageMutationDto"]; function AdministrationLanguagesEdit() { const p = Route.useParams(); const q = useQueryClient(); - const carer = useSuspenseQuery( - $api.queryOptions("get", "/languages/{id}", { - params: { path: { id: p.id } }, - }) - ); + const { data, isSuccess } = $api.useSuspenseQuery("get", "/languages/{id}", { + params: { path: { id: p.id } }, + }); + const n = useNavigate(); const editCarerMutation = $api.useMutation("patch", "/languages/{id}", { onSuccess: () => { @@ -40,9 +39,9 @@ function AdministrationLanguagesEdit() { }; useEffect(() => { - f.setValues(carer.data ?? {}); + f.setValues({ ...data, participant: data.participant?.id }); f.resetDirty(); - }, [carer.isSuccess, carer.data]); + }, [isSuccess, data]); return ( <> @@ -60,10 +59,6 @@ function AdministrationLanguagesEdit() { export const Route = createFileRoute("/_auth/administration/languages/edit/$id")({ loader: ({ params, context: { queryClient } }) => - queryClient.ensureQueryData( - $api.queryOptions("get", "/languages/{id}", { - params: { path: { id: params.id } }, - }) - ), + queryClient.ensureQueryData($api.queryOptions("get", "/languages/{id}", { params: { path: params } })), component: AdministrationLanguagesEdit, });