Skip to content

Commit

Permalink
fix(application-plc): Detect user delegation type (#16429)
Browse files Browse the repository at this point in the history
* wip

* wip

* Small fixes

* Conditioned

* Fixed messages

* Fixed conditionals
  • Loading branch information
kksteini authored Oct 16, 2024
1 parent d356a2f commit d25d4e9
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions libs/application/core/src/lib/fieldBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ export const buildMessageWithLinkButtonField = (
): MessageWithLinkButtonField => {
const { id, title, url, message, buttonTitle, marginBottom, marginTop } = data
return {
...extractCommonFields(data),
children: undefined,
id,
title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FetchError } from '@island.is/clients/middlewares'
import { NationalRegistryClientService } from '@island.is/clients/national-registry-v2'
import { isCompany } from 'kennitala'
import { coreErrorMessages } from '@island.is/application/core'
import { AuthDelegationType } from '@island.is/shared/types'

@Injectable()
export class ParliamentaryListCreationService extends BaseTemplateApiService {
Expand Down Expand Up @@ -84,6 +85,15 @@ export class ParliamentaryListCreationService extends BaseTemplateApiService {
return identity
}

async delegatedToCompany({ auth }: TemplateApiModuleActionProps) {
const data = {
delegatedToCompany:
auth.delegationType?.includes(AuthDelegationType.ProcurationHolder) ??
false,
}
return data
}

async submit({ application, auth }: TemplateApiModuleActionProps) {
const answers = application.answers as CreateListSchema
const parliamentaryCollection = application.externalData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export const ParliamentaryIdentityApi = defineTemplateApi({
action: 'parliamentaryIdentity',
order: 2,
})

export const IsDelegatedToCompanyApi = defineTemplateApi({
action: 'delegatedToCompany',
})
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,33 @@ export const Done: Form = buildForm({
component: 'CopyLink',
}),
buildMessageWithLinkButtonField({
condition: (_, externalData) => {
return !(
externalData?.delegatedToCompany.data as {
delegatedToCompany: boolean
}
).delegatedToCompany
},
id: 'done.goToServicePortal',
title: '',
url: '/minarsidur/min-gogn/listar/althingis-medmaelasofnun',
buttonTitle: m.linkFieldButtonTitle,
message: m.linkFieldMessage,
}),
buildMessageWithLinkButtonField({
condition: (_, externalData) => {
return (
externalData?.delegatedToCompany.data as {
delegatedToCompany: boolean
}
).delegatedToCompany
},
id: 'done.goToServicePortalCompany',
title: '',
url: '/minarsidur/fyrirtaeki/listar/althingis-medmaelasofnun',
buttonTitle: m.linkFieldButtonCompanyTitle,
message: m.linkFieldCompanyMessage,
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ParliamentaryCollectionApi,
CandidateApi,
ParliamentaryIdentityApi,
IsDelegatedToCompanyApi,
} from '../dataProviders'

export const Prerequisites: Form = buildForm({
Expand Down Expand Up @@ -90,6 +91,11 @@ export const Prerequisites: Form = buildForm({
title: '',
subTitle: '',
}),
buildDataProviderItem({
provider: IsDelegatedToCompanyApi,
title: '',
subTitle: '',
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ParliamentaryCollectionApi,
CandidateApi,
ParliamentaryIdentityApi,
IsDelegatedToCompanyApi,
} from '../dataProviders'
import { AuthDelegationType } from '@island.is/shared/types'

Expand Down Expand Up @@ -81,6 +82,7 @@ const createListTemplate: ApplicationTemplate<
CandidateApi,
ParliamentaryCollectionApi,
ParliamentaryIdentityApi,
IsDelegatedToCompanyApi,
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,20 @@ export const m = defineMessages({
linkFieldMessage: {
id: 'plc.application:linkFieldMessage',
defaultMessage:
'Á mínum síðum sést hve mörgum meðmælum hefur verið safnað í hverjum landsfjórðungi.',
'Á mínum síðum sést hve mörgum meðmælum hefur verið safnað í hverju kjördæmi.',
description: '',
},
linkFieldButtonCompanyTitle: {
id: 'plc.application:linkFieldButtonCompanyTitle',
defaultMessage: 'Mínar síður (fyrirtæki)',
description: '',
},
linkFieldCompanyMessage: {
id: 'plc.application:linkFieldCompanyMessage',
defaultMessage:
'Á mínum síðum fyrirtækja sést hve mörgum meðmælum hefur verið safnað í hverju kjördæmi.',
description: '',
},

/* Action Card logs */
logListCreated: {
id: 'plc.application:logListCreated',
Expand Down

0 comments on commit d25d4e9

Please sign in to comment.