Skip to content

Commit dcd0a48

Browse files
committed
move queries and mutations to query.ts
1 parent 8310d89 commit dcd0a48

File tree

2 files changed

+180
-181
lines changed
  • app/[locale]/dashboard/[entityType]/[entitySlug]/usecases/edit/[id]/contributors

2 files changed

+180
-181
lines changed

app/[locale]/dashboard/[entityType]/[entitySlug]/usecases/edit/[id]/contributors/page.tsx

Lines changed: 8 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -13,176 +13,8 @@ import { Loading } from '@/components/loading';
1313
import { useEditStatus } from '../../context';
1414
import CustomCombobox from './CustomCombobox';
1515
import EntitySection from './EntitySelection';
16+
import { FetchUsers, FetchUsecaseInfo, AddContributors, RemoveContributor, AddSupporters, RemoveSupporters, AddPartners, RemovePartners } from './query';
1617

17-
const FetchUsers: any = graphql(`
18-
query searchUsers($limit: Int!, $searchTerm: String!) {
19-
searchUsers(limit: $limit, searchTerm: $searchTerm) {
20-
id
21-
fullName
22-
username
23-
}
24-
}
25-
`);
26-
27-
const FetchUsecaseInfo: any = graphql(`
28-
query useCaseinfo($filters: UseCaseFilter) {
29-
useCases(filters: $filters) {
30-
id
31-
title
32-
contributors {
33-
id
34-
fullName
35-
username
36-
}
37-
supportingOrganizations {
38-
id
39-
name
40-
logo {
41-
url
42-
name
43-
}
44-
}
45-
partnerOrganizations{
46-
id
47-
name
48-
logo{
49-
url
50-
name
51-
}
52-
}
53-
}
54-
}
55-
`);
56-
57-
const AddContributors: any = graphql(`
58-
mutation addContributorToUseCase($useCaseId: String!, $userId: ID!) {
59-
addContributorToUseCase(useCaseId: $useCaseId, userId: $userId) {
60-
__typename
61-
... on TypeUseCase {
62-
id
63-
title
64-
contributors {
65-
id
66-
fullName
67-
username
68-
}
69-
}
70-
}
71-
}
72-
`);
73-
74-
const RemoveContributor: any = graphql(`
75-
mutation removeContributorFromUseCase($useCaseId: String!, $userId: ID!) {
76-
removeContributorFromUseCase(useCaseId: $useCaseId, userId: $userId) {
77-
__typename
78-
... on TypeUseCase {
79-
id
80-
title
81-
contributors {
82-
id
83-
fullName
84-
username
85-
}
86-
}
87-
}
88-
}
89-
`);
90-
91-
const AddSupporters: any = graphql(`
92-
mutation addSupportingOrganizationToUseCase(
93-
$useCaseId: String!
94-
$organizationId: ID!
95-
) {
96-
addSupportingOrganizationToUseCase(
97-
useCaseId: $useCaseId
98-
organizationId: $organizationId
99-
) {
100-
__typename
101-
... on TypeUseCaseOrganizationRelationship {
102-
organization {
103-
id
104-
name
105-
logo {
106-
url
107-
name
108-
}
109-
}
110-
}
111-
}
112-
}
113-
`);
114-
115-
const RemoveSupporters: any = graphql(`
116-
mutation removeSupportingOrganizationFromUseCase(
117-
$useCaseId: String!
118-
$organizationId: ID!
119-
) {
120-
removeSupportingOrganizationFromUseCase(
121-
useCaseId: $useCaseId
122-
organizationId: $organizationId
123-
) {
124-
__typename
125-
... on TypeUseCaseOrganizationRelationship {
126-
organization {
127-
id
128-
name
129-
logo {
130-
url
131-
name
132-
}
133-
}
134-
}
135-
}
136-
}
137-
`);
138-
139-
const AddPartners: any = graphql(`
140-
mutation addPartnerOrganizationToUseCase(
141-
$useCaseId: String!
142-
$organizationId: ID!
143-
) {
144-
addPartnerOrganizationToUseCase(
145-
useCaseId: $useCaseId
146-
organizationId: $organizationId
147-
) {
148-
__typename
149-
... on TypeUseCaseOrganizationRelationship {
150-
organization {
151-
id
152-
name
153-
logo {
154-
url
155-
name
156-
}
157-
}
158-
}
159-
}
160-
}
161-
`);
162-
163-
const RemovePartners: any = graphql(`
164-
mutation removePartnerOrganizationFromUseCase(
165-
$useCaseId: String!
166-
$organizationId: ID!
167-
) {
168-
removePartnerOrganizationFromUseCase(
169-
useCaseId: $useCaseId
170-
organizationId: $organizationId
171-
) {
172-
__typename
173-
... on TypeUseCaseOrganizationRelationship {
174-
organization {
175-
id
176-
name
177-
logo {
178-
url
179-
name
180-
}
181-
}
182-
}
183-
}
184-
}
185-
`);
18618

18719
const Details = () => {
18820
const params = useParams<{ id: string }>();
@@ -346,24 +178,19 @@ const Details = () => {
346178

347179
const { setStatus } = useEditStatus();
348180

349-
useEffect(() => {
350-
setStatus(
351-
addContributorLoading ||
352-
removeContributorLoading ||
353-
addSupporterLoading ||
354-
removeSupporterLoading ||
355-
addPartnerLoading
356-
? 'loading'
357-
: 'success'
358-
); // update based on mutation state
359-
}, [
181+
182+
const loadingStates = [
360183
addContributorLoading,
361184
removeContributorLoading,
362185
addSupporterLoading,
363186
removeSupporterLoading,
364187
addPartnerLoading,
365-
]);
188+
removePartnerLoading,
189+
];
366190

191+
useEffect(() => {
192+
setStatus(loadingStates.some(Boolean) ? 'loading' : 'success');
193+
}, loadingStates);
367194

368195
return (
369196
<div>
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import { graphql } from '@/gql';
2+
3+
4+
export const FetchUsers: any = graphql(`
5+
query searchUsers($limit: Int!, $searchTerm: String!) {
6+
searchUsers(limit: $limit, searchTerm: $searchTerm) {
7+
id
8+
fullName
9+
username
10+
}
11+
}
12+
`);
13+
14+
export const FetchUsecaseInfo: any = graphql(`
15+
query useCaseinfo($filters: UseCaseFilter) {
16+
useCases(filters: $filters) {
17+
id
18+
title
19+
contributors {
20+
id
21+
fullName
22+
username
23+
}
24+
supportingOrganizations {
25+
id
26+
name
27+
logo {
28+
url
29+
name
30+
}
31+
}
32+
partnerOrganizations{
33+
id
34+
name
35+
logo{
36+
url
37+
name
38+
}
39+
}
40+
}
41+
}
42+
`);
43+
44+
export const AddContributors: any = graphql(`
45+
mutation addContributorToUseCase($useCaseId: String!, $userId: ID!) {
46+
addContributorToUseCase(useCaseId: $useCaseId, userId: $userId) {
47+
__typename
48+
... on TypeUseCase {
49+
id
50+
title
51+
contributors {
52+
id
53+
fullName
54+
username
55+
}
56+
}
57+
}
58+
}
59+
`);
60+
61+
export const RemoveContributor: any = graphql(`
62+
mutation removeContributorFromUseCase($useCaseId: String!, $userId: ID!) {
63+
removeContributorFromUseCase(useCaseId: $useCaseId, userId: $userId) {
64+
__typename
65+
... on TypeUseCase {
66+
id
67+
title
68+
contributors {
69+
id
70+
fullName
71+
username
72+
}
73+
}
74+
}
75+
}
76+
`);
77+
78+
export const AddSupporters: any = graphql(`
79+
mutation addSupportingOrganizationToUseCase(
80+
$useCaseId: String!
81+
$organizationId: ID!
82+
) {
83+
addSupportingOrganizationToUseCase(
84+
useCaseId: $useCaseId
85+
organizationId: $organizationId
86+
) {
87+
__typename
88+
... on TypeUseCaseOrganizationRelationship {
89+
organization {
90+
id
91+
name
92+
logo {
93+
url
94+
name
95+
}
96+
}
97+
}
98+
}
99+
}
100+
`);
101+
102+
export const RemoveSupporters: any = graphql(`
103+
mutation removeSupportingOrganizationFromUseCase(
104+
$useCaseId: String!
105+
$organizationId: ID!
106+
) {
107+
removeSupportingOrganizationFromUseCase(
108+
useCaseId: $useCaseId
109+
organizationId: $organizationId
110+
) {
111+
__typename
112+
... on TypeUseCaseOrganizationRelationship {
113+
organization {
114+
id
115+
name
116+
logo {
117+
url
118+
name
119+
}
120+
}
121+
}
122+
}
123+
}
124+
`);
125+
126+
export const AddPartners: any = graphql(`
127+
mutation addPartnerOrganizationToUseCase(
128+
$useCaseId: String!
129+
$organizationId: ID!
130+
) {
131+
addPartnerOrganizationToUseCase(
132+
useCaseId: $useCaseId
133+
organizationId: $organizationId
134+
) {
135+
__typename
136+
... on TypeUseCaseOrganizationRelationship {
137+
organization {
138+
id
139+
name
140+
logo {
141+
url
142+
name
143+
}
144+
}
145+
}
146+
}
147+
}
148+
`);
149+
150+
export const RemovePartners: any = graphql(`
151+
mutation removePartnerOrganizationFromUseCase(
152+
$useCaseId: String!
153+
$organizationId: ID!
154+
) {
155+
removePartnerOrganizationFromUseCase(
156+
useCaseId: $useCaseId
157+
organizationId: $organizationId
158+
) {
159+
__typename
160+
... on TypeUseCaseOrganizationRelationship {
161+
organization {
162+
id
163+
name
164+
logo {
165+
url
166+
name
167+
}
168+
}
169+
}
170+
}
171+
}
172+
`);

0 commit comments

Comments
 (0)