Skip to content

Commit

Permalink
feat(company role): support optional agreements (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
lavanya-bmw authored May 22, 2024
1 parent 01cbad8 commit 7a2824a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

- Company Role
- Support optional agreements for company role

## 2.0.0-RC1

### Change
Expand Down
72 changes: 50 additions & 22 deletions src/components/cax-companyRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,17 @@ export const CompanyRoleCax = () => {
{agreement.name}
</span>{' '}
{t('companyRole.TermsAndCondSpan3')}
<span style={{ color: 'red' }}>
{agreement.mandatory ? ' *' : ''}
</span>
</>
) : (
<span>{agreement.name}</span>
<>
<span>{agreement.name}</span>
<span style={{ color: 'red' }}>
{agreement.mandatory ? ' *' : ''}
</span>
</>
)}
</p>
) : (
Expand All @@ -197,33 +205,53 @@ export const CompanyRoleCax = () => {
}

const nextClick = async () => {
setSubmitError(false)
const companyRoles = Object.keys(companyRoleChecked).filter(
(item) => companyRoleChecked[item]
)

const agreements = Object.keys(agreementChecked)
.filter((agreementId) => agreementChecked[agreementId])
.map((agreementId) => {
return {
agreementId,
consentStatus: 'ACTIVE',
}
})
const agreementsToBeChecked = allConsentData.companyRoles
.filter((item) => companyRoles.includes(item.companyRole))
.map((i) => i.agreementIds)
.flat()

const data = {
companyRoles,
agreements,
}
const checkedAgreements = Object.keys(agreementChecked).filter(
(i) => agreementChecked[i]
)

const mandatoryAgreementsToBeChecked = allConsentData.agreements
.filter((item) => agreementsToBeChecked.includes(item.agreementId))
.filter((i) => i.mandatory)
.map((agreement) => agreement.agreementId)

await updateAgreementConsents({ applicationId, data })
.unwrap()
.then(() => {
dispatch(addCurrentStep(currentActiveStep + 1))
})
.catch((errors) => {
console.log('errors', errors)
setSubmitError(true)
})
const valid = mandatoryAgreementsToBeChecked.every((i) =>
checkedAgreements.includes(i)
)

if (valid) {
const agreements = Object.keys(agreementChecked)
.filter((agreementId) => agreementChecked[agreementId])
.map((agreementId) => {
return {
agreementId,
consentStatus: 'ACTIVE',
}
})

const data = {
companyRoles,
agreements,
}

await updateAgreementConsents({ applicationId, data })
.unwrap()
.then(() => {
dispatch(addCurrentStep(currentActiveStep + 1))
})
.catch((errors) => {
setSubmitError(true)
})
} else setSubmitError(true)
}

const renderSnackbar = (message: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type AgreementData = {
name: string
agreementLink: string
documentId: string
mandatory: boolean
}

export type AgreementResponse = {
Expand Down

0 comments on commit 7a2824a

Please sign in to comment.