Skip to content

Commit

Permalink
fix(AOSH): Fixing a few minor bugs on AOSH applications (#14898)
Browse files Browse the repository at this point in the history
* Fixing payment bug for AOSH,
Removing date field,
Fixing Contentful script,
Adding error logs for emails and sms for AOSH,
Few message fixes,
Fixing location component and adding moreInfo text in locationSection

* Removing unused

* removing console.log

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
davidkef and kodiakhq[bot] authored May 24, 2024
1 parent 65c4d2e commit d40dac8
Show file tree
Hide file tree
Showing 28 changed files with 180 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const generateApplicationRejectedEmail: ApplicationRejectedEmail = (
`<span>Beiðni um eigendaskipti á tækinu ${regNumber} hefur verið afturkölluð þar sem eftirfarandi aðilar staðfestu ekki:</span><br/>` +
`<ul><li><p>${rejectedByStr}</p></li></ul>` +
`<span>Til þess að skrá eigendaskiptin rafrænt verður að byrja ferlið að upp á nýtt á umsóknarvef island.is: island.is/umsoknir, ásamt því að allir aðilar þurfa að staðfesta rafrænt innan gefins tímafrests.</span><br/>` +
`<span>Þessi tilkynning á aðeins við um rafræna umsókn af umsóknarvef island.is en ekki um eigendaskipti sem skilað hefur verið inn til Vinnueftirlitsins á pappír.</span><br/>` +
`<span>Vinsamlegast hafið samband við Vinnueftirlitið [email protected] ef nánari upplýsinga er þörf.</span>`,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,9 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
async submitApplication({
application,
auth,
currentUserLocale,
}: TemplateApiModuleActionProps): Promise<void> {
// Validate payment
// Make sure a paymentUrl was created
const { paymentUrl } = application.externalData.createCharge.data as {
paymentUrl: string
}
if (!paymentUrl) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}

// Make sure payment is fulfilled (has been paid)
const payment: { fulfilled: boolean } | undefined =
await this.sharedTemplateAPIService.getPaymentStatus(auth, application.id)
if (!payment?.fulfilled) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}
await this.handlePayment({ application, auth, currentUserLocale })

// Confirm owner change in AOSH
const answers = application.answers as TransferOfMachineOwnershipAnswers
Expand Down Expand Up @@ -141,9 +124,10 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
generateApplicationSubmittedEmail(props, recipientList[i]),
application,
)
.catch(() => {
.catch((e) => {
this.logger.error(
`Error sending email about submit application to ${recipientList[i].email}`,
e,
)
})
}
Expand All @@ -155,9 +139,10 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
generateApplicationSubmittedSms(application, recipientList[i]),
application,
)
.catch(() => {
.catch((e) => {
this.logger.error(
`Error sending sms about submit application to ${recipientList[i].phone}`,
e,
)
})
}
Expand All @@ -166,32 +151,22 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
async initReview({
application,
auth,
currentUserLocale,
}: TemplateApiModuleActionProps): Promise<Array<EmailRecipient>> {
// 1. Validate payment

// 1a. Make sure a paymentUrl was created
const { paymentUrl, id: paymentId } = application.externalData.createCharge
.data as {
paymentUrl: string
id: string
}
const answers = application.answers as TransferOfMachineOwnershipAnswers

if (!paymentUrl) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}

// 1b. Make sure payment is fulfilled (has been paid)
const payment: { fulfilled: boolean } | undefined =
await this.sharedTemplateAPIService.getPaymentStatus(auth, application.id)
if (!payment?.fulfilled) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
if (
answers.machine.paymentRequiredForOwnerChange &&
application.state === 'draft'
) {
return []
}
const paymentId = await this.handlePayment({
application,
auth,
currentUserLocale,
})

const answers = application.answers as TransferOfMachineOwnershipAnswers
const machineId = answers.machine.id || answers.pickMachine.id
if (!machineId) {
throw new Error('Ekki er búið að velja vél')
Expand Down Expand Up @@ -221,9 +196,10 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
(props) => generateRequestReviewEmail(props, recipientList[i]),
application,
)
.catch(() => {
.catch((e) => {
this.logger.error(
`Error sending email about initReview to ${recipientList[i].email}`,
e,
)
})
}
Expand All @@ -235,16 +211,57 @@ export class TransferOfMachineOwnershipTemplateService extends BaseTemplateApiSe
generateRequestReviewSms(application, options, recipientList[i]),
application,
)
.catch(() => {
.catch((e) => {
this.logger.error(
`Error sending sms about initReview to ${recipientList[i].phone}`,
e,
)
})
}
}

return recipientList
}

private async handlePayment({
application,
auth,
}: TemplateApiModuleActionProps): Promise<string | null> {
const answers = application.answers as TransferOfMachineOwnershipAnswers

if (answers.machine.paymentRequiredForOwnerChange) {
// 1. Validate payment

// 1a. Make sure a paymentUrl was created

const { paymentUrl = '', id: paymentId = '' } = (application.externalData
?.createCharge?.data ?? {}) as {
paymentUrl: string
id: string
}

if (!paymentUrl) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}

// 1b. Make sure payment is fulfilled (has been paid)
const payment: { fulfilled: boolean } | undefined =
await this.sharedTemplateAPIService.getPaymentStatus(
auth,
application.id,
)
if (!payment?.fulfilled) {
throw new Error(
'Ekki er búið að staðfesta greiðslu, hinkraðu þar til greiðslan er staðfest.',
)
}
return paymentId
}
return null
}

async rejectApplication({
application,
auth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,6 @@ export const machineSubSection = buildSubSection({
return machine?.plate || ''
},
}),
buildDateField({
id: 'machine.date',
title: information.labels.machine.date,
required: false,
width: 'half',
maxDate: new Date(),
minDate: () => {
const minDate = new Date()
minDate.setDate(minDate.getDate() - 7)
return minDate
},
defaultValue: new Date().toISOString().substring(0, 10),
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const pickMachineSubSection = buildSubSection({
description: information.labels.pickMachine.description,
children: [
buildRadioField({
id: 'pickMachine.id',
id: 'machine.id',
title: information.labels.pickMachine.title,
condition: (_, externalData) => {
const machines = getValueViaPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
const machineId = getValueViaPath(answers, 'pickMachine.id', '') as Machine
if (answers.findVehicle) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}

const machineId = getValueViaPath(answers, 'machine.id', '') as Machine
const machinesWithTotal = getValueViaPath(
externalData,
'machinesList.data',
{},
) as MachinesWithTotalCount

return machinesWithTotal.machines.find((machine) => machine.id === machineId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const pickMachineSubSection = buildSubSection({
description: information.labels.pickMachine.description,
children: [
buildRadioField({
id: 'pickMachine.id',
id: 'machine.id',
title: information.labels.pickMachine.title,
condition: (_, externalData) => {
const machines = getValueViaPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
const machineId = getValueViaPath(answers, 'pickMachine.id', '') as Machine
const machines = getValueViaPath(
if (answers.findVehicle) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}

const machineId = getValueViaPath(answers, 'machine.id', '') as Machine
const machinesWithTotal = getValueViaPath(
externalData,
'machinesList.data',
{},
) as MachinesWithTotalCount
return machines.machines.find((machine) => machine.id === machineId)

return machinesWithTotal.machines.find((machine) => machine.id === machineId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"extract-strings": {
"executor": "nx:run-commands",
"options": {
"command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/application/templates/aosh/request-for-inspection1/src/**/*.{js,ts,tsx}'"
"command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/application/templates/aosh/request-for-inspection/src/**/*.{js,ts,tsx}'"
}
},
"test": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const pickMachineSubSection = buildSubSection({
alertType: 'info',
}),
buildRadioField({
id: 'pickMachine.id',
id: 'machine.id',
title: information.labels.pickMachine.title,
condition: (_, externalData) => {
const machines = getValueViaPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const conclusion = {
description: 'Conclusion seller alert message',
},
alertTitle: {
id: 'aosh.rifm.application:conclusion.default.alertMessage',
id: 'aosh.rifm.application:conclusion.default.alertTitle',
defaultMessage: 'Beiðni um skoðun á tæki hefur verið móttekin!',
description: 'Conclusion seller alert title',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
const machineId = getValueViaPath(answers, 'pickMachine.id', '') as Machine
if (answers.findVehicle) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}

const machineId = getValueViaPath(answers, 'machine.id', '') as Machine
const machinesWithTotal = getValueViaPath(
externalData,
'machinesList.data',
{},
) as MachinesWithTotalCount

return machinesWithTotal.machines.find((machine) => machine.id === machineId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const pickMachineSubSection = buildSubSection({
description: information.labels.pickMachine.description,
children: [
buildRadioField({
id: 'pickMachine.id',
id: 'machine.id',
title: '',
condition: (_, externalData) => {
const machines = getValueViaPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
const machineId = getValueViaPath(answers, 'pickMachine.id', '') as Machine
const machines = getValueViaPath(
if (answers.findVehicle) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}

const machineId = getValueViaPath(answers, 'machine.id', '') as Machine
const machinesWithTotal = getValueViaPath(
externalData,
'machinesList.data',
{},
) as MachinesWithTotalCount
return machines.machines.find((machine) => machine.id === machineId)

return machinesWithTotal.machines.find((machine) => machine.id === machineId)
}

export const mustInspectBeforeStreetRegistration = (
Expand Down
Loading

0 comments on commit d40dac8

Please sign in to comment.