Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable delete for assistants #197

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-dolphins-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@quassel/frontend": patch
---

Disable delete for assistants
25 changes: 15 additions & 10 deletions apps/frontend/src/routes/_auth/administration/carers/index.tsx
Original file line number Diff line number Diff line change
@@ -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);

Check warning on line 8 in apps/frontend/src/routes/_auth/administration/carers/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/carers/index.tsx#L8

Added line #L8 was not covered by tests
const carers = $api.useSuspenseQuery("get", "/carers");
const deleteCarerMutation = $api.useMutation("delete", "/carers/{id}", {
onSuccess: () => carers.refetch(),
Expand All @@ -29,16 +32,18 @@
<Button variant="default" renderRoot={(props) => <Link to={`/administration/carers/edit/${c.id}`} {...props} />}>
Edit
</Button>
<Button
variant="default"
onClick={() =>
deleteCarerMutation.mutate({
params: { path: { id: c.id.toString() } },
})
}
>
Delete
</Button>
{sessionStore.role === "ADMIN" && (
<Button
variant="default"
onClick={() =>
deleteCarerMutation.mutate({
params: { path: { id: c.id.toString() } },
})

Check warning on line 41 in apps/frontend/src/routes/_auth/administration/carers/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/carers/index.tsx#L35-L41

Added lines #L35 - L41 were not covered by tests
}
>

Check warning on line 43 in apps/frontend/src/routes/_auth/administration/carers/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/carers/index.tsx#L43

Added line #L43 was not covered by tests
Delete
</Button>

Check warning on line 45 in apps/frontend/src/routes/_auth/administration/carers/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/carers/index.tsx#L45

Added line #L45 was not covered by tests
)}
</Table.Td>
</Table.Tr>
))}
Expand Down
25 changes: 15 additions & 10 deletions apps/frontend/src/routes/_auth/administration/languages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
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);

Check warning on line 9 in apps/frontend/src/routes/_auth/administration/languages/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/languages/index.tsx#L9

Added line #L9 was not covered by tests
const languages = useSuspenseQuery($api.queryOptions("get", "/languages"));
const deleteLanguageMutation = $api.useMutation("delete", "/languages/{id}", {
onSuccess: () => languages.refetch(),
Expand Down Expand Up @@ -32,16 +35,18 @@
<Button variant="default" renderRoot={(props) => <Link to={`/administration/languages/edit/${l.id}`} {...props} />}>
Edit
</Button>
<Button
variant="default"
onClick={() =>
deleteLanguageMutation.mutate({
params: { path: { id: l.id.toString() } },
})
}
>
Delete
</Button>
{sessionStore.role === "ADMIN" && (
<Button
variant="default"
onClick={() =>
deleteLanguageMutation.mutate({
params: { path: { id: l.id.toString() } },
})

Check warning on line 44 in apps/frontend/src/routes/_auth/administration/languages/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/languages/index.tsx#L38-L44

Added lines #L38 - L44 were not covered by tests
}
>

Check warning on line 46 in apps/frontend/src/routes/_auth/administration/languages/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/languages/index.tsx#L46

Added line #L46 was not covered by tests
Delete
</Button>

Check warning on line 48 in apps/frontend/src/routes/_auth/administration/languages/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/languages/index.tsx#L48

Added line #L48 was not covered by tests
)}
</Table.Td>
</Table.Tr>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
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);

Check warning on line 9 in apps/frontend/src/routes/_auth/administration/participants/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/participants/index.tsx#L9

Added line #L9 was not covered by tests
const participants = useSuspenseQuery($api.queryOptions("get", "/participants"));
const deleteParticipantMutation = $api.useMutation("delete", "/participants/{id}", {
onSuccess: () => participants.refetch(),
Expand Down Expand Up @@ -34,16 +37,18 @@
<Button variant="default" renderRoot={(props) => <Link to={`/administration/participants/edit/${p.id}`} {...props} />}>
Edit
</Button>
<Button
variant="default"
onClick={() =>
deleteParticipantMutation.mutate({
params: { path: { id: p.id.toString() } },
})
}
>
Delete
</Button>
{sessionStore.role === "ADMIN" && (
<Button
variant="default"
onClick={() =>
deleteParticipantMutation.mutate({
params: { path: { id: p.id.toString() } },
})

Check warning on line 46 in apps/frontend/src/routes/_auth/administration/participants/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/participants/index.tsx#L40-L46

Added lines #L40 - L46 were not covered by tests
}
>

Check warning on line 48 in apps/frontend/src/routes/_auth/administration/participants/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/participants/index.tsx#L48

Added line #L48 was not covered by tests
Delete
</Button>

Check warning on line 50 in apps/frontend/src/routes/_auth/administration/participants/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/participants/index.tsx#L50

Added line #L50 was not covered by tests
)}
</Table.Td>
</Table.Tr>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

Check warning on line 8 in apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx#L8

Added line #L8 was not covered by tests
const { data, refetch } = $api.useSuspenseQuery("get", "/questionnaires");
const deleteQuestionnaireMutation = $api.useMutation("delete", "/questionnaires/{id}", {
onSuccess: () => refetch(),
Expand All @@ -25,16 +28,18 @@
<Button variant="default" renderRoot={(props) => <Link to={`/administration/questionnaires/edit/${q.id}`} {...props} />}>
Edit
</Button>
<Button
variant="default"
onClick={() =>
deleteQuestionnaireMutation.mutate({
params: { path: { id: q.id.toString() } },
})
}
>
Delete
</Button>
{sessionStore.role === "ADMIN" && (
<Button
variant="default"
onClick={() =>
deleteQuestionnaireMutation.mutate({
params: { path: { id: q.id.toString() } },
})

Check warning on line 37 in apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx#L31-L37

Added lines #L31 - L37 were not covered by tests
}
>

Check warning on line 39 in apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx#L39

Added line #L39 was not covered by tests
Delete
</Button>

Check warning on line 41 in apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/questionnaires/index.tsx#L41

Added line #L41 was not covered by tests
)}
</Table.Td>
</Table.Tr>
))}
Expand Down
25 changes: 15 additions & 10 deletions apps/frontend/src/routes/_auth/administration/studies/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
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);

Check warning on line 9 in apps/frontend/src/routes/_auth/administration/studies/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/studies/index.tsx#L9

Added line #L9 was not covered by tests
const studies = useSuspenseQuery($api.queryOptions("get", "/studies"));
const deleteStudyMutation = $api.useMutation("delete", "/studies/{id}", {
onSuccess: () => studies.refetch(),
Expand All @@ -30,16 +33,18 @@
<Button variant="default" renderRoot={(props) => <Link to={`/administration/studies/edit/${s.id}`} {...props} />}>
Edit
</Button>
<Button
variant="default"
onClick={() =>
deleteStudyMutation.mutate({
params: { path: { id: s.id.toString() } },
})
}
>
Delete
</Button>
{sessionStore.role === "ADMIN" && (
<Button
variant="default"
onClick={() =>
deleteStudyMutation.mutate({
params: { path: { id: s.id.toString() } },
})

Check warning on line 42 in apps/frontend/src/routes/_auth/administration/studies/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/studies/index.tsx#L36-L42

Added lines #L36 - L42 were not covered by tests
}
>

Check warning on line 44 in apps/frontend/src/routes/_auth/administration/studies/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/studies/index.tsx#L44

Added line #L44 was not covered by tests
Delete
</Button>

Check warning on line 46 in apps/frontend/src/routes/_auth/administration/studies/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/studies/index.tsx#L46

Added line #L46 was not covered by tests
)}
</Table.Td>
</Table.Tr>
))}
Expand Down
11 changes: 8 additions & 3 deletions apps/frontend/src/routes/_auth/administration/users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
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);

Check warning on line 9 in apps/frontend/src/routes/_auth/administration/users/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/users/index.tsx#L9

Added line #L9 was not covered by tests
const users = useSuspenseQuery($api.queryOptions("get", "/users"));
const deleteUserMutation = $api.useMutation("delete", "/users/{id}", { onSuccess: () => users.refetch() });

Expand Down Expand Up @@ -31,9 +34,11 @@
<Button variant="default" renderRoot={(props) => <Link to={`/administration/users/edit/${u.id}`} {...props} />}>
Edit
</Button>
<Button variant="default" onClick={() => deleteUserMutation.mutate({ params: { path: { id: u.id.toString() } } })}>
Delete
</Button>
{sessionStore.role === "ADMIN" && (
<Button variant="default" onClick={() => deleteUserMutation.mutate({ params: { path: { id: u.id.toString() } } })}>

Check warning on line 38 in apps/frontend/src/routes/_auth/administration/users/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/users/index.tsx#L37-L38

Added lines #L37 - L38 were not covered by tests
Delete
</Button>

Check warning on line 40 in apps/frontend/src/routes/_auth/administration/users/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/users/index.tsx#L40

Added line #L40 was not covered by tests
)}
</Table.Td>
</Table.Tr>
))}
Expand Down
8 changes: 3 additions & 5 deletions apps/frontend/src/stores/session.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { persistentMap } from "@nanostores/persistent";
import { components } from "../api.gen";

type Session = {
email?: string;
role?: string;
};
type Session = Partial<Omit<components["schemas"]["SessionResponseDto"], "id">>;

export const $session = persistentMap<Session>("session:", {});
export const $session = persistentMap<Session>("session", {});
Loading