Skip to content

Commit

Permalink
Handle Draft MHR Corrections (#1858)
Browse files Browse the repository at this point in the history
* Enable save for later buttons
* Handle save and edit Draft Mhr Corrections
* Handle stale drafts
  • Loading branch information
dimak1 authored May 8, 2024
1 parent 5e50715 commit 03b827f
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 37 deletions.
11 changes: 8 additions & 3 deletions ppr-ui/src/components/common/ButtonFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ import {
ButtonConfigIF, DialogOptionsIF, DraftIF, ErrorIF, FinancingStatementIF, RegTableNewItemI, StateModelIF
} from '@/interfaces'
import { unsavedChangesDialog } from '@/resources/dialogOptions'
import { useNavigation, useNewMhrRegistration } from '@/composables'
import { useMhrCorrections, useNavigation, useNewMhrRegistration } from '@/composables'
import { storeToRefs } from 'pinia'
export default defineComponent({
Expand Down Expand Up @@ -174,10 +174,13 @@ export default defineComponent({
hasUnsavedChanges,
isRoleStaffBcol,
isRoleStaffReg,
isRoleStaffSbc
isRoleStaffSbc,
getMhrInformation
} = storeToRefs(useStore())
const { mhrDraftHandler } = useNewMhrRegistration()
const { isMhrCorrection } = useMhrCorrections()
const localState = reactive({
options: props.baseDialogOptions as DialogOptionsIF || unsavedChangesDialog,
showCancelDialog: false,
Expand Down Expand Up @@ -229,6 +232,7 @@ export default defineComponent({
const saveDraft = async (): Promise<boolean> => {
let draft
let prevDraftId
localState.submitting = true
if (props.isMhr) {
draft = await mhrDraftHandler()
Expand All @@ -248,7 +252,8 @@ export default defineComponent({
const newItem: RegTableNewItemI = {
addedReg: draft.financingStatement?.documentId || draft.draftNumber,
addedRegParent: '',
// adding mhrNumber will scroll to draft mhr correction
addedRegParent: isMhrCorrection.value ? getMhrInformation.value.mhrNumber : '',
addedRegSummary: null,
prevDraft: prevDraftId
}
Expand Down
21 changes: 20 additions & 1 deletion ppr-ui/src/components/common/RegistrationsWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ import {
} from '@/resources/dialogOptions'
import { StatusCodes } from 'http-status-codes'
import { cloneDeep } from 'lodash'
import { useExemptions, useNavigation, useNewMhrRegistration } from '@/composables'
import { useExemptions, useMhrCorrections, useNavigation, useNewMhrRegistration } from '@/composables'
export default defineComponent({
name: 'RegistrationsWrapper',
Expand Down Expand Up @@ -338,6 +338,9 @@ export default defineComponent({
initNewManufacturerMhr,
fetchMhRegistrations
} = useNewMhrRegistration(true)
const { initDraftMhrCorrection } = useMhrCorrections()
const { goToExemptions } = useExemptions()
const localState = reactive({
Expand Down Expand Up @@ -705,6 +708,16 @@ export default defineComponent({
}
openMhr(mhrInfo)
break
case TableActions.OPEN_DRAFT_CORRECTION:
if (mhrInfo.outOfDate) {
// Handle stale drafts before opening the MHR when flagged as outOfDate
localState.staleDraftId = mhrInfo?.draftNumber
localState.mhrWithDraftId = mhrInfo?.mhrNumber
localState.staleDraftDialogDisplay = true
return
}
openDraftMhrCorrection(mhrInfo)
break
case UnitNoteDocTypes.RESIDENTIAL_EXEMPTION_ORDER:
case UnitNoteDocTypes.NON_RESIDENTIAL_EXEMPTION:
openMhrExemption(mhrInfo, action)
Expand Down Expand Up @@ -755,6 +768,12 @@ export default defineComponent({
await router.replace({ name: RouteNames.MHR_INFORMATION })
}
const openDraftMhrCorrection = async (draftMhrCorrection) => {
await initDraftMhrCorrection(draftMhrCorrection)
// Navigate to MHR Corrections home route
goToRoute(RouteNames.SUBMITTING_PARTY)
}
const openMhrExemption = async (mhrSummary: MhRegistrationSummaryIF, type: UnitNoteDocTypes): Promise<void> => {
await setMhrInformation(mhrSummary)
await goToExemptions(type)
Expand Down
18 changes: 15 additions & 3 deletions ppr-ui/src/components/tables/common/TableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,22 @@ export default defineComponent({
}
const openMhr = (item: MhRegistrationSummaryIF): void => {
let action: TableActions
switch (item.registrationType) {
case APIMhrTypes.REGISTRY_STAFF_ADMIN:
action = TableActions.OPEN_DRAFT_CORRECTION
break
case APIMhrTypes.MANUFACTURED_HOME_REGISTRATION:
action = item.draftNumber ? TableActions.EDIT_NEW_MHR : TableActions.OPEN_MHR
break
default:
action = TableActions.OPEN_MHR
break
}
emit('action', {
action: (item.registrationType === APIMhrTypes.MANUFACTURED_HOME_REGISTRATION && item.draftNumber)
? TableActions.EDIT_NEW_MHR
: TableActions.OPEN_MHR,
action: action,
mhrInfo: item
})
}
Expand Down
53 changes: 47 additions & 6 deletions ppr-ui/src/composables/mhrRegistration/useMhrCorrections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
deleteEmptyProperties,
fetchMhRegistration,
fromDisplayPhone,
getFeatureFlag
getFeatureFlag,
getMhrDraft
} from '@/utils'
import { ActionTypes, APIRegistrationTypes, HomeCertificationOptions, RouteNames } from '@/enums'
import { useNavigation, useNewMhrRegistration } from '@/composables'
Expand All @@ -18,11 +19,14 @@ import {
UpdatedBadgeIF
} from '@/interfaces'
import { cloneDeep, omit } from 'lodash'
import { MhrCorrectionClient, MhrCorrectionStaff } from '@/resources/registrationTypes'

export const useMhrCorrections = () => {
const {
setMhrBaseline,
setRegistrationType,
setMhrDraftNumber,
setMhrStatusType
} = useStore()
const {
getMhrStatusType,
Expand All @@ -39,7 +43,7 @@ export const useMhrCorrections = () => {
} = storeToRefs(useStore())

const { containsCurrentRoute, goToRoute } = useNavigation()
const { initDraftOrCurrentMhr } = useNewMhrRegistration(true)
// const { initDraftOrCurrentMhr } = useNewMhrRegistration(true)

/** Returns true for staff when the feature flag is enabled **/
const isMhrChangesEnabled: ComputedRef<boolean> = computed((): boolean => {
Expand Down Expand Up @@ -217,9 +221,9 @@ export const useMhrCorrections = () => {
// Fetch current MHR Data
const { data } = await fetchMhRegistration(getMhrInformation.value.mhrNumber)

// Handle 'certificationOption' or 'noCertification' value mapping (because it's not returner in response)
const certificationOption = (data?.description?.csaNumber && HomeCertificationOptions.CSA) ||
(data?.description?.engineerName && HomeCertificationOptions.ENGINEER_INSPECTION) || null
// Handle 'certificationOption' or 'noCertification' value mapping (because it's not returned in response)
const certificationOption = (data?.description?.csaNumber && HomeCertificationOptions.CSA) ||
(data?.description?.engineerName && HomeCertificationOptions.ENGINEER_INSPECTION) || null

// Preserve MHR snapshot
await setMhrBaseline(cloneDeep({
Expand All @@ -233,12 +237,48 @@ export const useMhrCorrections = () => {
}))

// Set Current Registration to filing state
await initDraftOrCurrentMhr(data, true)
await useNewMhrRegistration(true).initDraftOrCurrentMhr(data, true)

// Navigate to MHR home route
await goToRoute(RouteNames.SUBMITTING_PARTY)
}

const initDraftMhrCorrection = async (draftMhrCorrection): Promise<void> => {

const draftNumber = draftMhrCorrection.draftNumber

// Fetch draft MHR Data
const { registration } = await getMhrDraft(draftNumber)
// Fetch original MHR Data (before the draft correction updates)
const { data } = await fetchMhRegistration(draftMhrCorrection.mhrNumber)

const correctionType: RegistrationTypeIF = [MhrCorrectionStaff, MhrCorrectionClient]
.find((corr: RegistrationTypeIF) => corr.registrationTypeAPI === registration.documentType)

setRegistrationType(correctionType)
setMhrDraftNumber(draftNumber)

// Handle 'certificationOption' or 'noCertification' value mapping (because it's not returned in response)
const certificationOption = (data?.description?.csaNumber && HomeCertificationOptions.CSA) ||
(data?.description?.engineerName && HomeCertificationOptions.ENGINEER_INSPECTION) || null

// Set MHR data as baseline state
await setMhrBaseline(cloneDeep({
...data,
description: {
...data.description,
certificationOption: certificationOption,
hasNoCertification: certificationOption === null,
},
statusType: data?.status
}))

await setMhrStatusType(data?.status)

// Set draft registration as current state
await useNewMhrRegistration(true).initDraftOrCurrentMhr(registration)
}

/**
* Corrects the details of a given home section.
* This function modifies the `homeSectionToCorrect` object directly by adjusting its
Expand Down Expand Up @@ -337,6 +377,7 @@ export const useMhrCorrections = () => {
correctAmendLabel,
hasMadeMhrCorrections,
initMhrCorrection,
initDraftMhrCorrection,
correctHomeSection,
buildLocationChange,
buildCorrectionPayload
Expand Down
37 changes: 30 additions & 7 deletions ppr-ui/src/composables/mhrRegistration/useNewMhrRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import {
MhrDraftIF
, StaffPaymentIF
} from '@/interfaces'
import { APIMhrTypes, HomeTenancyTypes, HomeLocationTypes, MhApiStatusTypes, HomeCertificationOptions } from '@/enums'
import {
APIMhrTypes,
HomeTenancyTypes,
HomeLocationTypes,
MhApiStatusTypes,
HomeCertificationOptions
} from '@/enums'
import {
cleanEmpty,
createMhrDraft,
Expand All @@ -23,7 +29,7 @@ import {
updateMhrDraft
} from '@/utils'
import { orderBy } from 'lodash'
import { useHomeOwners } from '@/composables'
import { useHomeOwners, useMhrCorrections } from '@/composables'

export const useNewMhrRegistration = (isMhrCorrections: boolean = false) => {
const {
Expand Down Expand Up @@ -53,13 +59,17 @@ export const useNewMhrRegistration = (isMhrCorrections: boolean = false) => {
getMhrRegistrationHomeOwnerGroups,
getMhrRegistrationOwnLand,
getStaffPayment,
getMhrDraftNumber
getMhrDraftNumber,
getRegistrationType,
getMhrInformation
} = storeToRefs(useStore())
const {
setShowGroups,
getHomeTenancyType
} = useHomeOwners(false, isMhrCorrections)

const { isMhrCorrection } = useMhrCorrections()

const initNewMhr = (): MhrRegistrationIF => {
return {
draftNumber: '',
Expand Down Expand Up @@ -181,7 +191,7 @@ export const useNewMhrRegistration = (isMhrCorrections: boolean = false) => {

// Set description
for (const [key, val] of Object.entries(initNewMhr().description)) {
mhrData.description[key]
mhrData?.description[key]
? setMhrHomeDescription({ key, value: mhrData.description[key] })
: setMhrHomeDescription({ key, value: val }) // set missing description values to default
}
Expand Down Expand Up @@ -347,6 +357,12 @@ export const useNewMhrRegistration = (isMhrCorrections: boolean = false) => {
data.draftNumber = getMhrDraftNumber.value
}

// add additional props to payload for Mhr Corrections
if (isMhrCorrection.value) {
data.documentType = getRegistrationType.value?.registrationTypeAPI
data.mhrNumber = getMhrInformation.value.mhrNumber
}

return data
}

Expand All @@ -358,9 +374,14 @@ export const useNewMhrRegistration = (isMhrCorrections: boolean = false) => {
}

const mhrDraftHandler = async (): Promise<MhrDraftIF> => {

const draftType = isMhrCorrection.value
? APIMhrTypes.REGISTRY_STAFF_ADMIN
: APIMhrTypes.MANUFACTURED_HOME_REGISTRATION

const draft = getMhrDraftNumber.value
? await updateMhrDraft(getMhrDraftNumber.value, APIMhrTypes.MANUFACTURED_HOME_REGISTRATION, buildApiData())
: await createMhrDraft(APIMhrTypes.MANUFACTURED_HOME_REGISTRATION, buildApiData())
? await updateMhrDraft(getMhrDraftNumber.value, draftType, buildApiData())
: await createMhrDraft(draftType, buildApiData())

// Set draftNumber to state to prevent duplicate drafts
if (draft) setMhrDraftNumber(draft.draftNumber)
Expand All @@ -380,7 +401,8 @@ export const useNewMhrRegistration = (isMhrCorrections: boolean = false) => {

if (!sortOptions?.status || sortOptions?.status === MhApiStatusTypes.DRAFT) {
mhRegDrafts = mhrDrafts?.filter(draft =>
!draft.mhrNumber && draft.registrationType === APIMhrTypes.MANUFACTURED_HOME_REGISTRATION
!draft.mhrNumber && [APIMhrTypes.MANUFACTURED_HOME_REGISTRATION, APIMhrTypes.REGISTRY_STAFF_ADMIN]
.includes(draft.registrationType as APIMhrTypes)
)
}

Expand Down Expand Up @@ -415,6 +437,7 @@ export const useNewMhrRegistration = (isMhrCorrections: boolean = false) => {
clientReferenceId: transfer.clientReferenceId,
createDateTime: draft.createDateTime,
error: draft.error,
registrationType: draft.registrationType,
registrationDescription: draft.registrationDescription,
hasDraft: false,
ownerNames: '',
Expand Down
1 change: 1 addition & 0 deletions ppr-ui/src/enums/errorCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum ErrorCategories {
DOCUMENT_ID = 'document-id',
DRAFT_DELETE = 'draft-delete',
DRAFT_LOAD = 'draft-load',
DRAFT_OUT_OF_DATE = 'draft-stale',
ENTITY_BASIC = 'entity-basic',
FEE_INFO = 'fee-info',
HISTORY_REGISTRATIONS = 'history-registrations',
Expand Down
1 change: 1 addition & 0 deletions ppr-ui/src/enums/tableActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export enum TableActions {
REMOVE_TRANSFER_DRAFT = 'removeTransferDraft',
OPEN_MHR = 'openMhr',
EDIT_NEW_MHR = 'editMhr',
OPEN_DRAFT_CORRECTION = 'openDraftCorrection'
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export interface MhrRegistrationIF {
export interface NewMhrRegistrationApiIF {
draftNumber?: string
documentId?: string
documentType?: string
mhrNumber?: string
registrationType?: APIRegistrationTypes,
clientReferenceId?: string
declaredValue?: string
submittingParty: SubmittingPartyIF,
Expand Down
Loading

0 comments on commit 03b827f

Please sign in to comment.