Skip to content

Commit

Permalink
fix(signature-collection): sign list without candidateid
Browse files Browse the repository at this point in the history
  • Loading branch information
albinagu committed Sep 25, 2024
1 parent a85feae commit 2a0be84
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
buildDescriptionField,
buildForm,
buildHiddenInput,
buildMultiField,
buildRadioField,
buildSection,
buildSubmitField,
buildTextField,
Expand All @@ -20,7 +20,7 @@ export const Draft: Form = buildForm({
title: '',
mode: FormModes.DRAFT,
renderLastScreenButton: true,
renderLastScreenBackButton: true,
renderLastScreenBackButton: false,
logo: Logo,
children: [
buildSection({
Expand All @@ -33,6 +33,60 @@ export const Draft: Form = buildForm({
title: m.dataCollection,
children: [],
}),
/* section used for testing purposes */
buildSection({
id: 'selectCandidateSection',
title: m.selectCandidate,
condition: (_, externalData) => {
const lists = getValueViaPath(
externalData,
'getList.data',
[],
) as SignatureCollectionList[]
return lists.length > 1
},
children: [
buildMultiField({
id: 'selectCandidateSection',
title: m.selectCandidate,
description: m.selectCandidateDescription,
children: [
buildRadioField({
id: 'listId',
title: '',
defaultValue: '',
required: true,
options: ({
externalData: {
getList: { data },
},
}) => {
return (data as SignatureCollectionList[]).map((list) => ({
value: list.id,
label: list.candidate.name,
disabled:
list.maxReached || new Date(list.endTime) < new Date(),
tag: list.maxReached
? {
label: m.selectCandidateMaxReached.defaultMessage,
variant: 'red',
outlined: true,
}
: new Date(list.endTime) < new Date()
? {
label: m.selectCandidateListExpired.defaultMessage,
variant: 'red',
outlined: true,
}
: undefined,
}))
},
}),
],
}),
],
}),
/* ------------------------------- */
buildSection({
id: 'signListInformationSection',
title: m.information,
Expand All @@ -47,24 +101,7 @@ export const Draft: Form = buildForm({
title: m.listHeader,
titleVariant: 'h3',
}),
buildHiddenInput({
id: 'listId',
defaultValue: ({ answers, externalData }: Application) => {
const lists = getValueViaPath(
externalData,
'getList.data',
[],
) as SignatureCollectionList[]

const initialQuery = getValueViaPath(
answers,
'initialQuery',
'',
)

return lists.find((x) => x.candidate.id === initialQuery)?.id
},
}),
buildTextField({
id: 'list.name',
title: m.listName,
Expand All @@ -83,7 +120,11 @@ export const Draft: Form = buildForm({
'',
)

return lists.find((x) => x.candidate.id === initialQuery)?.title
return lists.find((list) =>
initialQuery
? list.candidate.id === initialQuery
: list.id === answers.listId,
)?.candidate?.name
},
}),
buildTextField({
Expand All @@ -104,8 +145,11 @@ export const Draft: Form = buildForm({
'',
)

return lists.find((x) => x.candidate.id === initialQuery)
?.candidate?.partyBallotLetter
return lists.find((list) =>
initialQuery
? list.candidate.id === initialQuery
: list.id === answers.listId,
)?.candidate?.partyBallotLetter
},
}),
buildDescriptionField({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ export const Prerequisites: Form = buildForm({
title: '',
subTitle: '',
}),
buildDataProviderItem({
//provider: TODO: Add providers needed for signing collection,
title: '',
subTitle: '',
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { z } from 'zod'
export const dataSchema = z.object({
/* Gagnaöflun */
approveExternalData: z.boolean().refine((v) => v),
listId: z.string().min(1),
list: z.object({
name: z.string(),
letter: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ export const m = defineMessages({
defaultMessage: 'Nafn',
description: '',
},
selectCandidate: {
id: 'pls.application:selectCandidate',
defaultMessage: 'Veldu frambjóðanda',
description: '',
},
selectCandidateDescription: {
id: 'pls.application:selectCandidateDescription',
defaultMessage: 'Frambjóðendur á þínu svæði sem hægt er að mæla með:',
description: '',
},
selectCandidateMaxReached: {
id: 'pls.application:selectCandidateMaxReached',
defaultMessage: 'Hámarki meðmæla náð',
description: '',
},
selectCandidateListExpired: {
id: 'pls.application:selectCandidateListExpired',
defaultMessage: 'Söfnuninni lokið',
description: '',
},
listName: {
id: 'pls.application:listName',
defaultMessage: 'Heiti framboðs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import { dataSchema } from './dataSchema'
import { m } from './messages'
import { EphemeralStateLifeCycle } from '@island.is/application/core'
import { Features } from '@island.is/feature-flags'
import {
CanSignApi,
CurrentCollectionApi,
GetListApi,
OwnerRequirementsApi,
} from '../dataProviders'
import { CanSignApi, CurrentCollectionApi, GetListApi } from '../dataProviders'

const WeekLifeCycle: StateLifeCycle = {
shouldBeListed: false,
Expand Down

0 comments on commit 2a0be84

Please sign in to comment.