Skip to content

Commit e9edd28

Browse files
fix(signature-collection): Admin create lists fix (#16491)
* waiting for national-registry endpoint * add new national-registry endpoint + ui updates --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent f031834 commit e9edd28

File tree

5 files changed

+110
-18
lines changed

5 files changed

+110
-18
lines changed

libs/clients/signature-collection/src/clientConfig.json

+37
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,41 @@
112112
}
113113
}
114114
},
115+
"/Admin/Medmaelalisti": {
116+
"post": {
117+
"tags": ["Admin"],
118+
"summary": "Bætir við nýjum meðmælalistum fyrir þegar stofnað framboð",
119+
"requestBody": {
120+
"description": "",
121+
"content": {
122+
"application/json": {
123+
"schema": {
124+
"$ref": "#/components/schemas/MedmaelalistarRequestDTO"
125+
}
126+
}
127+
}
128+
},
129+
"responses": {
130+
"200": {
131+
"description": "OK",
132+
"content": {
133+
"application/json": {
134+
"schema": {
135+
"type": "array",
136+
"items": { "$ref": "#/components/schemas/MedmaelalistiDTO" }
137+
}
138+
}
139+
}
140+
},
141+
"400": {
142+
"description": "Bad Request",
143+
"content": {
144+
"application/json": { "schema": { "type": "string" } }
145+
}
146+
}
147+
}
148+
}
149+
},
115150
"/Admin/Medmaelalisti/{ID}": {
116151
"delete": {
117152
"tags": ["Admin"],
@@ -928,7 +963,9 @@
928963
},
929964
"post": {
930965
"tags": ["Medmaelalistar"],
966+
"summary": "Bætir við nýjum meðmælalistum fyrir þegar stofnað framboð",
931967
"requestBody": {
968+
"description": "",
932969
"content": {
933970
"application/json": {
934971
"schema": {

libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts

+39-15
Original file line numberDiff line numberDiff line change
@@ -129,27 +129,51 @@ export class SignatureCollectionAdminClientService {
129129
throw new Error('Collection id input wrong')
130130
}
131131

132+
const candidates = await this.getApiWithAuth(
133+
this.candidateApi,
134+
auth,
135+
).frambodGet({
136+
sofnunID: parseInt(collectionId),
137+
})
138+
139+
const adminApi = await this.getApiWithAuth(this.adminApi, auth)
140+
132141
const filteredAreas = areas
133142
? collectionAreas.filter((area) =>
134143
areas.flatMap((a) => a.areaId).includes(area.id),
135144
)
136145
: collectionAreas
137146

138-
const candidacy = await this.getApiWithAuth(
139-
this.adminApi,
140-
auth,
141-
).adminFrambodPost({
142-
frambodRequestDTO: {
143-
sofnunID: parseInt(id),
144-
kennitala: owner.nationalId,
145-
simi: owner.phone,
146-
netfang: owner.email,
147-
medmaelalistar: filteredAreas.map((area) => ({
148-
svaediID: parseInt(area.id),
149-
listiNafn: `${owner.name} - ${area.name}`,
150-
})),
151-
},
152-
})
147+
let candidacy = candidates.find((c) => c.kennitala === owner.nationalId)
148+
149+
// If no candidacy exists, create one
150+
if (!candidacy) {
151+
candidacy = await adminApi.adminFrambodPost({
152+
frambodRequestDTO: {
153+
sofnunID: parseInt(id),
154+
kennitala: owner.nationalId,
155+
simi: owner.phone,
156+
netfang: owner.email,
157+
medmaelalistar: filteredAreas.map((area) => ({
158+
svaediID: parseInt(area.id),
159+
listiNafn: `${owner.name} - ${area.name}`,
160+
})),
161+
},
162+
})
163+
}
164+
// Candidacy exists, add area
165+
else {
166+
await adminApi.adminMedmaelalistiPost({
167+
medmaelalistarRequestDTO: {
168+
frambodID: candidacy.id,
169+
medmaelalistar: filteredAreas.map((area) => ({
170+
svaediID: parseInt(area.id),
171+
listiNafn: `${owner.name} - ${area.name}`,
172+
})),
173+
},
174+
})
175+
}
176+
153177
return {
154178
slug: getSlug(
155179
candidacy.id ?? '',

libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export const Constituency = ({
4848
(list) => list.area.name === constituencyName,
4949
)
5050

51+
const areaId = collection.areas.find((a) => a.name === constituencyName)?.id
52+
5153
const countCandidatesLists = (allLists: SignatureCollectionList[]) => {
5254
return allLists?.reduce((acc: any, list: SignatureCollectionList) => {
5355
acc[list.candidate.id] = (acc[list.candidate.id] || 0) + 1
@@ -126,7 +128,10 @@ export const Constituency = ({
126128
constituencyLists.length}
127129
</Text>
128130
{allowedToProcess && constituencyLists?.length > 0 && (
129-
<CreateCollection collectionId={collection?.id} />
131+
<CreateCollection
132+
collectionId={collection?.id}
133+
areaId={areaId}
134+
/>
130135
)}
131136
</Box>
132137
<Stack space={3}>

libs/portals/admin/signature-collection/src/screens-presidential/AllLists/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ const Lists = ({ allowedToProcess }: { allowedToProcess: boolean }) => {
221221
{lists?.length > 0 &&
222222
allowedToProcess &&
223223
collectionStatus === CollectionStatus.InInitialReview && (
224-
<CreateCollection collectionId={collection?.id} />
224+
<CreateCollection
225+
collectionId={collection?.id}
226+
areaId={undefined}
227+
/>
225228
)}
226229
</Box>
227230
</GridColumn>

libs/portals/admin/signature-collection/src/shared-components/createCollection/index.tsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ import { useCandidateLookupLazyQuery } from './candidateLookup.generated'
1818
import { setReason } from './utils'
1919
import { useCreateCollectionMutation } from './createCollection.generated'
2020
import { m } from '../../lib/messages'
21+
import { useParams, useRevalidator } from 'react-router-dom'
2122

22-
const CreateCollection = ({ collectionId }: { collectionId: string }) => {
23+
const CreateCollection = ({
24+
collectionId,
25+
areaId,
26+
}: {
27+
collectionId: string
28+
areaId: string | undefined
29+
}) => {
2330
const { formatMessage } = useLocale()
2431
const { control } = useForm()
32+
const { revalidate } = useRevalidator()
33+
const { constituencyName } = useParams() as {
34+
constituencyName: string | undefined
35+
}
2536

2637
const [modalIsOpen, setModalIsOpen] = useState(false)
2738
const [nationalIdInput, setNationalIdInput] = useState('')
@@ -42,8 +53,12 @@ const CreateCollection = ({ collectionId }: { collectionId: string }) => {
4253
phone: '',
4354
email: '',
4455
},
56+
areas: areaId ? [{ areaId }] : null,
4557
},
4658
},
59+
onCompleted: () => {
60+
revalidate()
61+
},
4762
})
4863

4964
const createNewCollection = async () => {
@@ -154,6 +169,14 @@ const CreateCollection = ({ collectionId }: { collectionId: string }) => {
154169
readOnly
155170
value={name}
156171
/>
172+
{areaId && (
173+
<Input
174+
name="candidateArea"
175+
label={formatMessage(m.signatureListsConstituencyTitle)}
176+
readOnly
177+
value={constituencyName}
178+
/>
179+
)}
157180
</Stack>
158181
{!canCreate && (
159182
<Box marginTop={3}>

0 commit comments

Comments
 (0)