From 7e7f2c95d0220d85f763a6270eb1066d53f4d92a Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 16 Dec 2024 16:37:13 +0000 Subject: [PATCH 1/2] feat: disasble delete for assistants --- .changeset/lovely-dolphins-tickle.md | 5 ++++ .../_auth/administration/carers/index.tsx | 25 +++++++++++-------- .../_auth/administration/languages/index.tsx | 25 +++++++++++-------- .../administration/participants/index.tsx | 25 +++++++++++-------- .../administration/questionnaires/index.tsx | 25 +++++++++++-------- .../_auth/administration/studies/index.tsx | 25 +++++++++++-------- .../_auth/administration/users/index.tsx | 11 +++++--- apps/frontend/src/stores/session.ts | 2 +- 8 files changed, 89 insertions(+), 54 deletions(-) create mode 100644 .changeset/lovely-dolphins-tickle.md diff --git a/.changeset/lovely-dolphins-tickle.md b/.changeset/lovely-dolphins-tickle.md new file mode 100644 index 0000000..3e1bc2f --- /dev/null +++ b/.changeset/lovely-dolphins-tickle.md @@ -0,0 +1,5 @@ +--- +"@quassel/frontend": patch +--- + +Disable delete for assistants diff --git a/apps/frontend/src/routes/_auth/administration/carers/index.tsx b/apps/frontend/src/routes/_auth/administration/carers/index.tsx index d9deac9..5aa3f4d 100644 --- a/apps/frontend/src/routes/_auth/administration/carers/index.tsx +++ b/apps/frontend/src/routes/_auth/administration/carers/index.tsx @@ -1,8 +1,11 @@ import { createFileRoute, Link } from "@tanstack/react-router"; import { $api } from "../../../../stores/api"; import { Button, Table } from "@quassel/ui"; +import { $session } from "../../../../stores/session"; +import { useStore } from "@nanostores/react"; function AdministrationCarersIndex() { + const sessionStore = useStore($session); const carers = $api.useSuspenseQuery("get", "/carers"); const deleteCarerMutation = $api.useMutation("delete", "/carers/{id}", { onSuccess: () => carers.refetch(), @@ -29,16 +32,18 @@ function AdministrationCarersIndex() { - + {sessionStore.role === "ADMIN" && ( + + )} ))} diff --git a/apps/frontend/src/routes/_auth/administration/languages/index.tsx b/apps/frontend/src/routes/_auth/administration/languages/index.tsx index 229eb3e..2d01953 100644 --- a/apps/frontend/src/routes/_auth/administration/languages/index.tsx +++ b/apps/frontend/src/routes/_auth/administration/languages/index.tsx @@ -2,8 +2,11 @@ import { createFileRoute, Link } from "@tanstack/react-router"; import { $api } from "../../../../stores/api"; import { Button, Table } from "@quassel/ui"; import { useSuspenseQuery } from "@tanstack/react-query"; +import { $session } from "../../../../stores/session"; +import { useStore } from "@nanostores/react"; function AdministrationLanguageIndex() { + const sessionStore = useStore($session); const languages = useSuspenseQuery($api.queryOptions("get", "/languages")); const deleteLanguageMutation = $api.useMutation("delete", "/languages/{id}", { onSuccess: () => languages.refetch(), @@ -32,16 +35,18 @@ function AdministrationLanguageIndex() { - + {sessionStore.role === "ADMIN" && ( + + )} ))} diff --git a/apps/frontend/src/routes/_auth/administration/participants/index.tsx b/apps/frontend/src/routes/_auth/administration/participants/index.tsx index 8b56385..77adfe1 100644 --- a/apps/frontend/src/routes/_auth/administration/participants/index.tsx +++ b/apps/frontend/src/routes/_auth/administration/participants/index.tsx @@ -2,8 +2,11 @@ import { createFileRoute, Link } from "@tanstack/react-router"; import { $api } from "../../../../stores/api"; import { Button, Table } from "@quassel/ui"; import { useSuspenseQuery } from "@tanstack/react-query"; +import { $session } from "../../../../stores/session"; +import { useStore } from "@nanostores/react"; function AdministrationParticipantsIndex() { + const sessionStore = useStore($session); const participants = useSuspenseQuery($api.queryOptions("get", "/participants")); const deleteParticipantMutation = $api.useMutation("delete", "/participants/{id}", { onSuccess: () => participants.refetch(), @@ -34,16 +37,18 @@ function AdministrationParticipantsIndex() { - + {sessionStore.role === "ADMIN" && ( + + )} ))} diff --git a/apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx b/apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx index 1614d56..d19ed77 100644 --- a/apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx +++ b/apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx @@ -1,8 +1,11 @@ import { createFileRoute, Link } from "@tanstack/react-router"; import { $api } from "../../../../stores/api"; import { Button, Table } from "@quassel/ui"; +import { $session } from "../../../../stores/session"; +import { useStore } from "@nanostores/react"; function AdministrationQuestionnairesIndex() { + const sessionStore = useStore($session); const { data, refetch } = $api.useSuspenseQuery("get", "/questionnaires"); const deleteQuestionnaireMutation = $api.useMutation("delete", "/questionnaires/{id}", { onSuccess: () => refetch(), @@ -25,16 +28,18 @@ function AdministrationQuestionnairesIndex() { - + {sessionStore.role === "ADMIN" && ( + + )} ))} diff --git a/apps/frontend/src/routes/_auth/administration/studies/index.tsx b/apps/frontend/src/routes/_auth/administration/studies/index.tsx index cca42b0..c68b83b 100644 --- a/apps/frontend/src/routes/_auth/administration/studies/index.tsx +++ b/apps/frontend/src/routes/_auth/administration/studies/index.tsx @@ -2,8 +2,11 @@ import { createFileRoute, Link } from "@tanstack/react-router"; import { $api } from "../../../../stores/api"; import { Button, Table } from "@quassel/ui"; import { useSuspenseQuery } from "@tanstack/react-query"; +import { $session } from "../../../../stores/session"; +import { useStore } from "@nanostores/react"; function AdministrationStudiesIndex() { + const sessionStore = useStore($session); const studies = useSuspenseQuery($api.queryOptions("get", "/studies")); const deleteStudyMutation = $api.useMutation("delete", "/studies/{id}", { onSuccess: () => studies.refetch(), @@ -30,16 +33,18 @@ function AdministrationStudiesIndex() { - + {sessionStore.role === "ADMIN" && ( + + )} ))} diff --git a/apps/frontend/src/routes/_auth/administration/users/index.tsx b/apps/frontend/src/routes/_auth/administration/users/index.tsx index 611df89..1f702b2 100644 --- a/apps/frontend/src/routes/_auth/administration/users/index.tsx +++ b/apps/frontend/src/routes/_auth/administration/users/index.tsx @@ -2,8 +2,11 @@ import { createFileRoute, Link } from "@tanstack/react-router"; import { $api } from "../../../../stores/api"; import { Button, Table } from "@quassel/ui"; import { useSuspenseQuery } from "@tanstack/react-query"; +import { useStore } from "@nanostores/react"; +import { $session } from "../../../../stores/session"; function AdministrationUsersIndex() { + const sessionStore = useStore($session); const users = useSuspenseQuery($api.queryOptions("get", "/users")); const deleteUserMutation = $api.useMutation("delete", "/users/{id}", { onSuccess: () => users.refetch() }); @@ -31,9 +34,11 @@ function AdministrationUsersIndex() { - + {sessionStore.role === "ADMIN" && ( + + )} ))} diff --git a/apps/frontend/src/stores/session.ts b/apps/frontend/src/stores/session.ts index 9cdc67a..4710776 100644 --- a/apps/frontend/src/stores/session.ts +++ b/apps/frontend/src/stores/session.ts @@ -5,4 +5,4 @@ type Session = { role?: string; }; -export const $session = persistentMap("session:", {}); +export const $session = persistentMap("session", {}); From 84170436494eb9ce7a208e8232f638467022744e Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 16 Dec 2024 16:55:28 +0000 Subject: [PATCH 2/2] chore: make session store more typesafe --- apps/frontend/src/stores/session.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/frontend/src/stores/session.ts b/apps/frontend/src/stores/session.ts index 4710776..2805e1f 100644 --- a/apps/frontend/src/stores/session.ts +++ b/apps/frontend/src/stores/session.ts @@ -1,8 +1,6 @@ import { persistentMap } from "@nanostores/persistent"; +import { components } from "../api.gen"; -type Session = { - email?: string; - role?: string; -}; +type Session = Partial>; export const $session = persistentMap("session", {});