Skip to content

Commit 42d5d2b

Browse files
committed
refactor: extract common mutations to separate files
1 parent 7c65990 commit 42d5d2b

File tree

6 files changed

+111
-60
lines changed

6 files changed

+111
-60
lines changed

frontend/app/api/generated.ts

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,28 @@ export type GetMeQueryVariables = Exact<{ [key: string]: never; }>;
14151415

14161416
export type GetMeQuery = { __typename?: 'Query', me: { __typename?: 'User', id: string, name: string, email: string, image?: string | null, membersId: string, gender: Gender, birthdate: string, church: { __typename?: 'Church', id: string, name: string, country: string, category: ChurchCategory }, roles: Array<{ __typename?: 'UserRole', id: string, role: RoleType, scope?: { __typename?: 'RoleScope', id: string, type: ScopeType, church?: { __typename?: 'Church', id: string } | null, team?: { __typename?: 'Team', id: string } | null, project?: { __typename?: 'Project', id: string } | null } | null }> } };
14171417

1418+
export type DeleteChallengeMutationVariables = Exact<{
1419+
challengeId: Scalars['ID']['input'];
1420+
}>;
1421+
1422+
1423+
export type DeleteChallengeMutation = { __typename?: 'Mutation', deleteChallenge: boolean };
1424+
1425+
export type CreateProjectMutationVariables = Exact<{
1426+
input: CreateProjectInput;
1427+
}>;
1428+
1429+
1430+
export type CreateProjectMutation = { __typename?: 'Mutation', createProject: { __typename?: 'Project', id: string } };
1431+
1432+
export type UpdateProjectMutationVariables = Exact<{
1433+
id: Scalars['ID']['input'];
1434+
input: UpdateProjectInput;
1435+
}>;
1436+
1437+
1438+
export type UpdateProjectMutation = { __typename?: 'Mutation', updateProject: { __typename?: 'Project', id: string } };
1439+
14181440
export type AdminSidebarQueryVariables = Exact<{ [key: string]: never; }>;
14191441

14201442

@@ -1437,14 +1459,6 @@ export type AdminProjectEditPageQueryVariables = Exact<{
14371459

14381460
export type AdminProjectEditPageQuery = { __typename?: 'Query', project: { __typename?: 'Project', id: string, name: string, description: string, startDate: any, endDate: any, archivedAt?: boolean | null, branding: { __typename?: 'Branding', logo?: string | null, rounding: number, colors: { __typename?: 'Colors', primary: string } } } };
14391461

1440-
export type UpdateProjectMutationVariables = Exact<{
1441-
id: Scalars['ID']['input'];
1442-
input: UpdateProjectInput;
1443-
}>;
1444-
1445-
1446-
export type UpdateProjectMutation = { __typename?: 'Mutation', updateProject: { __typename?: 'Project', id: string } };
1447-
14481462
export type AdminProjectPageQueryVariables = Exact<{
14491463
projectId: Scalars['ID']['input'];
14501464
}>;
@@ -1462,13 +1476,6 @@ export type AdminProjectsPageQueryVariables = Exact<{ [key: string]: never; }>;
14621476

14631477
export type AdminProjectsPageQuery = { __typename?: 'Query', projects: { __typename?: 'ProjectConnection', edges: Array<{ __typename?: 'ProjectEdge', node: { __typename?: 'Project', id: string, name: string, description: string, endDate: any, startDate: any, branding: { __typename?: 'Branding', logo?: string | null, colors: { __typename?: 'Colors', primary: string } } } }> } };
14641478

1465-
export type CreateProjectMutationVariables = Exact<{
1466-
input: CreateProjectInput;
1467-
}>;
1468-
1469-
1470-
export type CreateProjectMutation = { __typename?: 'Mutation', createProject: { __typename?: 'Project', id: string } };
1471-
14721479
export type AdminUserPageQueryVariables = Exact<{
14731480
id: Scalars['ID']['input'];
14741481
}>;
@@ -1556,6 +1563,37 @@ export const GetMeDocument = gql`
15561563
export function useGetMeQuery(options?: Omit<Urql.UseQueryArgs<never, GetMeQueryVariables | undefined>, 'query'>) {
15571564
return Urql.useQuery<GetMeQuery, GetMeQueryVariables | undefined>({ query: GetMeDocument, variables: undefined, ...options });
15581565
};
1566+
export const DeleteChallengeDocument = gql`
1567+
mutation DeleteChallenge($challengeId: ID!) {
1568+
deleteChallenge(id: $challengeId)
1569+
}
1570+
`;
1571+
1572+
export function useDeleteChallengeMutation() {
1573+
return Urql.useMutation<DeleteChallengeMutation, DeleteChallengeMutationVariables>(DeleteChallengeDocument);
1574+
};
1575+
export const CreateProjectDocument = gql`
1576+
mutation CreateProject($input: CreateProjectInput!) {
1577+
createProject(input: $input) {
1578+
id
1579+
}
1580+
}
1581+
`;
1582+
1583+
export function useCreateProjectMutation() {
1584+
return Urql.useMutation<CreateProjectMutation, CreateProjectMutationVariables>(CreateProjectDocument);
1585+
};
1586+
export const UpdateProjectDocument = gql`
1587+
mutation UpdateProject($id: ID!, $input: UpdateProjectInput!) {
1588+
updateProject(id: $id, input: $input) {
1589+
id
1590+
}
1591+
}
1592+
`;
1593+
1594+
export function useUpdateProjectMutation() {
1595+
return Urql.useMutation<UpdateProjectMutation, UpdateProjectMutationVariables>(UpdateProjectDocument);
1596+
};
15591597
export const AdminSidebarDocument = gql`
15601598
query AdminSidebar {
15611599
projects {
@@ -1646,17 +1684,6 @@ export const AdminProjectEditPageDocument = gql`
16461684
export function useAdminProjectEditPageQuery(options?: Omit<Urql.UseQueryArgs<never, AdminProjectEditPageQueryVariables | undefined>, 'query'>) {
16471685
return Urql.useQuery<AdminProjectEditPageQuery, AdminProjectEditPageQueryVariables | undefined>({ query: AdminProjectEditPageDocument, variables: undefined, ...options });
16481686
};
1649-
export const UpdateProjectDocument = gql`
1650-
mutation UpdateProject($id: ID!, $input: UpdateProjectInput!) {
1651-
updateProject(id: $id, input: $input) {
1652-
id
1653-
}
1654-
}
1655-
`;
1656-
1657-
export function useUpdateProjectMutation() {
1658-
return Urql.useMutation<UpdateProjectMutation, UpdateProjectMutationVariables>(UpdateProjectDocument);
1659-
};
16601687
export const AdminProjectPageDocument = gql`
16611688
query AdminProjectPage($projectId: ID!) {
16621689
project(id: $projectId) {
@@ -1673,31 +1700,31 @@ export const AdminProjectPageDocument = gql`
16731700
}
16741701
}
16751702
}
1676-
achievements(filter: {projectId: $projectId}) {
1703+
achievements(first: 50, filter: {projectId: $projectId}) {
16771704
edges {
16781705
node {
16791706
id
16801707
name
16811708
}
16821709
}
16831710
}
1684-
events(filter: {projectId: $projectId}) {
1711+
events(first: 50, filter: {projectId: $projectId}) {
16851712
edges {
16861713
node {
16871714
id
16881715
name
16891716
}
16901717
}
16911718
}
1692-
challenges(filter: {projectId: $projectId}) {
1719+
challenges(first: 50, filter: {projectId: $projectId}) {
16931720
edges {
16941721
node {
16951722
id
16961723
name
16971724
}
16981725
}
16991726
}
1700-
streaks(filter: {projectId: $projectId}) {
1727+
streaks(first: 50, filter: {projectId: $projectId}) {
17011728
edges {
17021729
node {
17031730
id
@@ -1736,17 +1763,6 @@ export const AdminProjectsPageDocument = gql`
17361763
export function useAdminProjectsPageQuery(options?: Omit<Urql.UseQueryArgs<never, AdminProjectsPageQueryVariables | undefined>, 'query'>) {
17371764
return Urql.useQuery<AdminProjectsPageQuery, AdminProjectsPageQueryVariables | undefined>({ query: AdminProjectsPageDocument, variables: undefined, ...options });
17381765
};
1739-
export const CreateProjectDocument = gql`
1740-
mutation CreateProject($input: CreateProjectInput!) {
1741-
createProject(input: $input) {
1742-
id
1743-
}
1744-
}
1745-
`;
1746-
1747-
export function useCreateProjectMutation() {
1748-
return Urql.useMutation<CreateProjectMutation, CreateProjectMutationVariables>(CreateProjectDocument);
1749-
};
17501766
export const AdminUserPageDocument = gql`
17511767
query AdminUserPage($id: ID!) {
17521768
user(id: $id) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mutation DeleteChallenge($challengeId: ID!) {
2+
deleteChallenge(id: $challengeId)
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mutation CreateProject($input: CreateProjectInput!) {
2+
createProject(input: $input) {
3+
id
4+
}
5+
}
6+
7+
mutation UpdateProject($id: ID!, $input: UpdateProjectInput!) {
8+
updateProject(id: $id, input: $input) {
9+
id
10+
}
11+
}

frontend/app/pages/admin/projects/[projectId]/edit.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ gql(`
2525
}
2626
}
2727
}
28-
29-
mutation UpdateProject($id: ID!, $input: UpdateProjectInput!) {
30-
updateProject(id: $id, input: $input) {
31-
id
32-
}
33-
}
3428
`)
3529
3630
const route = useRoute('admin-projects-projectId-edit')

frontend/app/pages/admin/projects/[projectId]/index.vue

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@ gql(`
2222
}
2323
}
2424
}
25-
achievements(filter: { projectId: $projectId }) {
25+
achievements(first: 50, filter: { projectId: $projectId }) {
2626
edges {
2727
node {
2828
id
2929
name
3030
}
3131
}
3232
}
33-
events(filter: { projectId: $projectId }) {
33+
events(first: 50, filter: { projectId: $projectId }) {
3434
edges {
3535
node {
3636
id
3737
name
3838
}
3939
}
4040
}
41-
challenges(filter: { projectId: $projectId }) {
41+
challenges(first: 50, filter: { projectId: $projectId }) {
4242
edges {
4343
node {
4444
id
4545
name
4646
}
4747
}
4848
}
49-
streaks(filter: { projectId: $projectId }) {
49+
streaks(first: 50, filter: { projectId: $projectId }) {
5050
edges {
5151
node {
5252
id
@@ -90,6 +90,26 @@ watch(data, () => {
9090
state.branding = data.value.project.branding
9191
}
9292
})
93+
94+
const toast = useToast()
95+
const { executeMutation } = useDeleteChallengeMutation()
96+
const deleteChallenge = (challengeId: string) => {
97+
executeMutation({ challengeId })
98+
.then(() => {
99+
toast.add({
100+
title: 'Challenge deleted',
101+
description: 'The challenge has been deleted',
102+
color: 'success',
103+
})
104+
})
105+
.catch((error) => {
106+
toast.add({
107+
title: error.name,
108+
description: error.message,
109+
color: 'error',
110+
})
111+
})
112+
}
93113
</script>
94114

95115
<template>
@@ -158,7 +178,22 @@ watch(data, () => {
158178
<UTable :data="data.events.edges.map((e) => e.node)" />
159179
</template>
160180
<template #challenges>
161-
<UTable :data="data.challenges.edges.map((e) => e.node)" />
181+
<UTable
182+
:data="data.challenges.edges.map((e) => e.node)"
183+
:columns="[
184+
{ accessorKey: 'id' },
185+
{ accessorKey: 'name' },
186+
{ id: 'action' },
187+
]"
188+
>
189+
<template #action-cell="{ row }">
190+
<UButton
191+
color="error"
192+
@click="() => deleteChallenge(row.original.id)"
193+
>Delete</UButton
194+
>
195+
</template>
196+
</UTable>
162197
</template>
163198
<template #streaks>
164199
<UTable :data="data.streaks.edges.map((e) => e.node)" />

frontend/app/pages/admin/projects/new.vue

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ definePageMeta({
77
middleware: 'admin',
88
})
99
10-
gql(`
11-
mutation CreateProject($input: CreateProjectInput!) {
12-
createProject(input: $input) {
13-
id
14-
}
15-
}
16-
`)
17-
1810
const schema = z.object({
1911
name: z.string().nonempty({ error: 'Name is required' }),
2012
description: z.string().optional(),

0 commit comments

Comments
 (0)