Skip to content

Commit 386b37a

Browse files
committed
add geographies to collaborative
1 parent 6ed1e43 commit 386b37a

File tree

4 files changed

+90
-32
lines changed

4 files changed

+90
-32
lines changed

app/[locale]/(user)/collaboratives/[collaborativeSlug]/CollaborativeDetailsClient.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ const CollaborativeDetails = graphql(`
6969
id
7070
value
7171
}
72+
geographies {
73+
id
74+
name
75+
code
76+
type
77+
}
7278
publishers {
7379
name
7480
contactEmail

app/[locale]/(user)/collaboratives/components/Details.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,23 @@ const PrimaryDetails = ({ data, isLoading }: { data: any; isLoading: any }) => {
114114
</div>
115115

116116
<div className=" lg:pr-4">
117-
<div className="mt-6 lg:mt-10">
118-
<Text variant="headingXl" color="onBgDefault">Geographies</Text>
119-
<div className="mt-4">
120-
<Tag
121-
fillColor="var(--orange-secondary-color)"
122-
borderColor="var(--orange-secondary-text)"
123-
textColor="white"
124-
>
125-
{
126-
data.collaborativeBySlug.metadata?.find(
127-
(meta: any) => meta.metadataItem?.label === 'Geography'
128-
)?.value
129-
}
130-
</Tag>
117+
{data.collaborativeBySlug.geographies && data.collaborativeBySlug.geographies.length > 0 && (
118+
<div className="mt-6 lg:mt-10">
119+
<Text variant="headingXl" color="onBgDefault">Geographies</Text>
120+
<div className="mt-4 flex flex-wrap gap-2">
121+
{data.collaborativeBySlug.geographies.map((geo: any, index: number) => (
122+
<Tag
123+
key={index}
124+
fillColor="var(--orange-secondary-color)"
125+
borderColor="var(--orange-secondary-text)"
126+
textColor="white"
127+
>
128+
{geo.name}
129+
</Tag>
130+
))}
131+
</div>
131132
</div>
132-
</div>
133+
)}
133134
<div className="mt-6 lg:mt-10">
134135
<Text variant="headingXl" color="onBgDefault">Summary</Text>
135136
<div className="mt-4">

app/[locale]/(user)/collaboratives/components/Metadata.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { useEffect, useState } from 'react';
21
import Image from 'next/image';
32
import Link from 'next/link';
43
import { Button, Divider, Icon, Text, Tooltip } from 'opub-ui';
4+
import { useEffect, useState } from 'react';
55

6-
import { formatDate, getWebsiteTitle } from '@/lib/utils';
76
import { Icons } from '@/components/icons';
7+
import { formatDate, getWebsiteTitle } from '@/lib/utils';
88

99
const Metadata = ({ data, setOpen }: { data: any; setOpen?: any }) => {
1010
const [platformTitle, setPlatformTitle] = useState<string | null>(null);
@@ -48,21 +48,6 @@ const Metadata = ({ data, setOpen }: { data: any; setOpen?: any }) => {
4848
),
4949
tooltipContent: data.collaborativeBySlug.platformUrl === null ? 'N/A' : platformTitle,
5050
},
51-
{
52-
label: 'Started On',
53-
value: formatDate(data.collaborativeBySlug.startedOn) || 'N/A',
54-
tooltipContent: formatDate(data.collaborativeBySlug.startedOn) || 'N/A',
55-
},
56-
{
57-
label: 'Completed On',
58-
value: formatDate(data.collaborativeBySlug.completedOn) || 'N/A',
59-
tooltipContent: formatDate(data.collaborativeBySlug.completedOn) || 'N/A',
60-
},
61-
{
62-
label: 'Status',
63-
value: data.collaborativeBySlug.status?.split('_').join('') || 'N/A',
64-
tooltipContent: data.collaborativeBySlug.status?.split('_').join('') || 'N/A',
65-
},
6651
{
6752
label: 'Last Updated',
6853
value: formatDate(data.collaborativeBySlug.modified) || 'N/A',

app/[locale]/dashboard/[entityType]/[entitySlug]/collaboratives/edit/[id]/metadata/page.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ const FetchCollaborativeMetadata: any = graphql(`
3636
code
3737
name
3838
}
39+
geographies {
40+
id
41+
name
42+
code
43+
type
44+
}
3945
}
4046
}
4147
`);
@@ -82,6 +88,21 @@ const tagsListQueryDoc: any = graphql(`
8288
}
8389
`);
8490

91+
const geographiesListQueryDoc: any = graphql(`
92+
query GeographiesList {
93+
geographies {
94+
id
95+
name
96+
code
97+
type
98+
parentId {
99+
id
100+
name
101+
}
102+
}
103+
}
104+
`);
105+
85106
const UpdateCollaborativeMetadata: any = graphql(`
86107
mutation addUpdateCollaborativeMetadata($updateMetadataInput: UpdateCollaborativeMetadataInput!) {
87108
addUpdateCollaborativeMetadata(updateMetadataInput: $updateMetadataInput) {
@@ -110,6 +131,12 @@ const UpdateCollaborativeMetadata: any = graphql(`
110131
code
111132
name
112133
}
134+
geographies {
135+
id
136+
name
137+
code
138+
type
139+
}
113140
}
114141
}
115142
}
@@ -201,6 +228,14 @@ const Metadata = () => {
201228
};
202229
}) || [];
203230

231+
defaultVal['geographies'] =
232+
data?.geographies?.map((geo: any) => {
233+
return {
234+
label: geo.name,
235+
value: geo.id,
236+
};
237+
}) || [];
238+
204239
return defaultVal;
205240
};
206241

@@ -253,6 +288,17 @@ const Metadata = () => {
253288
[]
254289
)
255290
);
291+
292+
const getGeographiesList: { data: any; isLoading: boolean; error: any } =
293+
useQuery([`geographies_list_query`], () =>
294+
GraphQL(
295+
geographiesListQueryDoc,
296+
{
297+
[params.entityType]: params.entitySlug,
298+
},
299+
[]
300+
)
301+
);
256302
const [isTagsListUpdated, setIsTagsListUpdated] = useState(false);
257303

258304
// Update mutation
@@ -307,6 +353,7 @@ const Metadata = () => {
307353
sectors: updatedData.sectors?.map((item: any) => item.value) || [],
308354
sdgs: updatedData.sdgs?.map((item: any) => item.value) || [],
309355
tags: updatedData.tags?.map((item: any) => item.label) || [],
356+
geographies: updatedData.geographies?.map((item: any) => parseInt(item.value, 10)) || [],
310357
},
311358
});
312359
}
@@ -320,6 +367,7 @@ const Metadata = () => {
320367
getSectorsList.isLoading ||
321368
getSDGsList.isLoading ||
322369
getTagsList.isLoading ||
370+
getGeographiesList.isLoading ||
323371
collaborativeData.isLoading
324372
) {
325373
return (
@@ -436,6 +484,24 @@ const Metadata = () => {
436484
}}
437485
/>
438486
</div>
487+
<div className="w-full py-4 pr-4 sm:w-1/2 md:w-1/2 lg:w-1/2 xl:w-1/2">
488+
<Combobox
489+
displaySelected
490+
label="Geographies"
491+
name="geographies"
492+
list={
493+
getGeographiesList?.data.geographies?.map((item: any) => ({
494+
label: `${item.name}${item.parentId ? ` (${item.parentId.name})` : ''}`,
495+
value: item.id,
496+
})) || []
497+
}
498+
selectedValue={formData.geographies}
499+
onChange={(value) => {
500+
handleChange('geographies', value);
501+
handleSave({ ...formData, geographies: value });
502+
}}
503+
/>
504+
</div>
439505
</div>
440506

441507
<div className="flex flex-wrap">

0 commit comments

Comments
 (0)