From 7831942aa2f4f909a88057889645830edfeb4712 Mon Sep 17 00:00:00 2001 From: Kial Date: Fri, 15 Nov 2024 12:25:26 -0500 Subject: [PATCH] UI - account/permit dashboard load data updates (#307) Signed-off-by: Kial Jinnah --- strr-base-web/app/composables/useStrrApi.ts | 2 +- .../app/composables/useStrrBasePermit.ts | 39 ++++------ .../app/enums/registration-status.ts | 6 ++ strr-base-web/app/interfaces/strr-api.ts | 8 +- strr-base-web/app/utils/dashboardHelpers.ts | 73 +++++++++---------- strr-platform-web/app/locales/en-CA.ts | 3 +- .../app/pages/platform/dashboard.vue | 19 ++--- strr-platform-web/app/stores/platform.ts | 2 +- ...egistrationId].vue => [applicationId].vue} | 18 +++-- .../pages/strata-hotel/dashboard/index.vue | 3 +- strr-strata-web/app/stores/strata.ts | 45 +++--------- 11 files changed, 96 insertions(+), 122 deletions(-) create mode 100644 strr-base-web/app/enums/registration-status.ts rename strr-strata-web/app/pages/strata-hotel/dashboard/{[registrationId].vue => [applicationId].vue} (92%) diff --git a/strr-base-web/app/composables/useStrrApi.ts b/strr-base-web/app/composables/useStrrApi.ts index 571b521b..958d8198 100644 --- a/strr-base-web/app/composables/useStrrApi.ts +++ b/strr-base-web/app/composables/useStrrApi.ts @@ -3,7 +3,7 @@ export const useStrrApi = () => { const { $strrApi } = useNuxtApp() const getAccountRegistrations = async ( - id?: string, + id?: number | string, type?: ApplicationType ) => { if (id) { diff --git a/strr-base-web/app/composables/useStrrBasePermit.ts b/strr-base-web/app/composables/useStrrBasePermit.ts index 6faa970f..d8bedae9 100644 --- a/strr-base-web/app/composables/useStrrBasePermit.ts +++ b/strr-base-web/app/composables/useStrrBasePermit.ts @@ -28,34 +28,25 @@ export const useStrrBasePermit = !!registration.value || (!!application.value && !isApplicationStatus([ApplicationStatus.DECLINED, ApplicationStatus.DRAFT]))) - const loadPermitData = async (id?: string) => { - if (id) { - // check if the id matches a registration under this account - registration.value = await getAccountRegistrations(id) as R - if (!registration.value) { - // No registrations under the account so get by application - application.value = await getAccountApplications(id) as A + const loadPermitData = async (applicationId?: string, applicationType?: ApplicationType) => { + if (applicationId) { + // Get specific application + application.value = await getAccountApplications(applicationId) as A + if (application.value?.header.registrationId) { + // Get linked registration if applicable + registration.value = await getAccountRegistrations( + application.value.header.registrationId) as R } } else { - const applications = await getAccountApplications() as A[] + // Get most recent application + const applications = await getAccountApplications(undefined, applicationType) as A[] if (applications.length) { - // set active strata to the most recent application (ordered by api: newest to oldest) + // Set active strata to the most recent application (ordered by api: newest to oldest) application.value = applications[0] - if (isApprovedApplication.value) { - // TODO: should be able to get a registration based on the application number and vice versa? - // get registrations under this account - const registrations = await getAccountRegistrations() as R[] - if ( - registrations.length && - // NOTE: below line is just for ts - (registrations[0] && application.value) && - registrations[0].startDate > application.value.header.applicationDateTime - ) { - // set active platform to the most recent registration - registration.value = registrations.sort( - // TODO: update once api allows sorting - (a, b) => new Date(b.startDate).getTime() - new Date(a.startDate).getTime())[0] - } + if (application.value?.header.registrationId) { + // Get linked registration if applicable + registration.value = await getAccountRegistrations( + application.value.header.registrationId) as R } } } diff --git a/strr-base-web/app/enums/registration-status.ts b/strr-base-web/app/enums/registration-status.ts new file mode 100644 index 00000000..113ba309 --- /dev/null +++ b/strr-base-web/app/enums/registration-status.ts @@ -0,0 +1,6 @@ +export enum RegistrationStatus { + ACTIVE = 'ACTIVE', + CANCELLED = 'CANCELLED', + EXPIRED = 'EXPIRED', + SUSPENDED = 'SUSPENDED' +} diff --git a/strr-base-web/app/interfaces/strr-api.ts b/strr-base-web/app/interfaces/strr-api.ts index 501e00ab..3ec1596e 100644 --- a/strr-base-web/app/interfaces/strr-api.ts +++ b/strr-base-web/app/interfaces/strr-api.ts @@ -52,7 +52,7 @@ export interface ApiExtraRegistrationDetails { registration_number: string sbc_account_id: number startDate: Date - status: 'ACTIVE' | 'CANCELLED' | 'EXPIRED' | 'SUSPENDED', + status: RegistrationStatus, updatedDate: Date user_id: number } @@ -71,6 +71,12 @@ export interface ApplicationHeader { paymentStatus: string paymentToken: string // invoice id status: ApplicationStatus + // below will only exist for applications that have a linked registration + registrationEndDate?: Date + registrationId?: number + registrationNumber?: string + registrationStartDate?: Date + registrationStatus?: RegistrationStatus } export interface ApiRegistrationResp extends ApiBaseRegistration, ApiExtraRegistrationDetails { } diff --git a/strr-base-web/app/utils/dashboardHelpers.ts b/strr-base-web/app/utils/dashboardHelpers.ts index e148baf6..ee2830fc 100644 --- a/strr-base-web/app/utils/dashboardHelpers.ts +++ b/strr-base-web/app/utils/dashboardHelpers.ts @@ -1,13 +1,43 @@ -export const setApplicationHeaderDetails = (receiptAction?: Function, hostStatus?: string) => { +export const setHeaderDetails = ( + status?: string | RegistrationStatus, + expiryDate?: string, + receiptAction?: Function +) => { // NOTE: even though this function is called within 'setup', useNuxtApp is required for the app context const { t } = useNuxtApp().$i18n const { details, bottomButtons } = storeToRefs(useConnectDetailsHeaderStore()) - if (hostStatus) { - details.value = [{ text: hostStatus, chip: true, chipColour: 'yellow' }] + if (status) { + const red = [ + RegistrationStatus.CANCELLED, + RegistrationStatus.EXPIRED, + RegistrationStatus.SUSPENDED].includes(status as RegistrationStatus) + + const yellow = status !== RegistrationStatus.ACTIVE + + details.value = [{ + text: status, + chip: true, + chipColour: red ? 'red' : yellow ? 'yellow' : undefined + }] + } + if (expiryDate) { + details.value.push({ text: `${t('label.expiryDate')} - ${expiryDate}` }) } if (receiptAction) { bottomButtons.value = [ + // TODO: add in later + // { + // action: () => { console.info('View and Change') }, + // label: 'View and Change Platform Information', + // icon: 'i-mdi-file-document-edit-outline' + // }, + // FUTURE: add back in once certificate is built + // { + // action: () => { console.info('Certificate') }, + // label: 'Certificate', + // icon: 'i-mdi-file-download-outline' + // }, { action: receiptAction, label: t('word.Receipt'), @@ -18,43 +48,6 @@ export const setApplicationHeaderDetails = (receiptAction?: Function, hostStatus } } -export const setRegistrationHeaderDetails = ( - status: ApplicationStatus, - expiryDate?: string, - receiptAction?: Function -) => { - // NOTE: even though this function is called within 'setup', useNuxtApp is required for the app context - const { t } = useNuxtApp().$i18n - const { details, bottomButtons } = storeToRefs(useConnectDetailsHeaderStore()) - - details.value = [{ text: status, chip: true }] - if (expiryDate) { - details.value.push({ text: `${t('label.expiryDate')} - ${expiryDate}` }) - } - bottomButtons.value = [ - // TODO: determine if this is a valid action / add label to locales - // { - // action: () => { console.info('View and Change') }, - // label: 'View and Change Platform Information', - // icon: 'i-mdi-file-document-edit-outline' - // }, - // FUTURE: add back in once certificate is built - // { - // action: () => { console.info('Certificate') }, - // label: 'Certificate', - // icon: 'i-mdi-file-download-outline' - // }, - ...(receiptAction - ? [{ - action: receiptAction, - label: t('word.Receipt'), - // TODO: find/replace with correct icon - icon: 'i-mdi-file-download-outline' - }] - : []) - ] -} - export const setSideHeaderDetails = ( business: StrrBusiness, registration?: ApiExtraRegistrationDetails, diff --git a/strr-platform-web/app/locales/en-CA.ts b/strr-platform-web/app/locales/en-CA.ts index 9e344344..d855acd5 100644 --- a/strr-platform-web/app/locales/en-CA.ts +++ b/strr-platform-web/app/locales/en-CA.ts @@ -56,7 +56,8 @@ export default { listingSize: { THOUSAND_AND_ABOVE: '1000 or more listings', BETWEEN_250_AND_999: '250-999 listings', - LESS_THAN_250: 'Less than 250 listings' + LESS_THAN_250: 'Less than 250 listings', + null: 'No Listings' }, noncomplianceEmail: 'Non-compliance Email', registeredOfficeAttorney: 'Registered Office / Attorney', diff --git a/strr-platform-web/app/pages/platform/dashboard.vue b/strr-platform-web/app/pages/platform/dashboard.vue index b15d2dad..da362831 100644 --- a/strr-platform-web/app/pages/platform/dashboard.vue +++ b/strr-platform-web/app/pages/platform/dashboard.vue @@ -46,18 +46,15 @@ onMounted(async () => { { text: t(`strr.label.listingSize.${platformDetails.value.listingSize}`) } ] if (!registration.value) { - setApplicationHeaderDetails( - isPaidApplication.value ? downloadApplicationReceipt : undefined, - application.value?.header.hostStatus) + setHeaderDetails( + application.value?.header.hostStatus, + undefined, + isPaidApplication.value ? downloadApplicationReceipt : undefined) } else { - const registrationDetails = permitDetails.value as ApiExtraRegistrationDetails - setRegistrationHeaderDetails( - registrationDetails.status as ApplicationStatus, - registrationDetails.expiryDate - ? dateToStringPacific(registrationDetails.expiryDate, 'MMMM Do, YYYY') - : undefined, - downloadApplicationReceipt - ) + setHeaderDetails( + permitDetails.value.status, + permitDetails.value.expiryDate, + downloadApplicationReceipt) } // add common side details setSideHeaderDetails( diff --git a/strr-platform-web/app/stores/platform.ts b/strr-platform-web/app/stores/platform.ts index 597d13be..10047d00 100644 --- a/strr-platform-web/app/stores/platform.ts +++ b/strr-platform-web/app/stores/platform.ts @@ -14,7 +14,7 @@ export const useStrrPlatformStore = defineStore('strr/platform', () => { } = useStrrBasePermit() const loadPlatform = async () => { - await loadPermitData() + await loadPermitData(undefined, ApplicationType.PLATFORM) if (application.value) { // set completing party info (this data is only in the application) completingParty.value = formatPartyUI(application.value.registration.completingParty) diff --git a/strr-strata-web/app/pages/strata-hotel/dashboard/[registrationId].vue b/strr-strata-web/app/pages/strata-hotel/dashboard/[applicationId].vue similarity index 92% rename from strr-strata-web/app/pages/strata-hotel/dashboard/[registrationId].vue rename to strr-strata-web/app/pages/strata-hotel/dashboard/[applicationId].vue index 661e1831..14427377 100644 --- a/strr-strata-web/app/pages/strata-hotel/dashboard/[registrationId].vue +++ b/strr-strata-web/app/pages/strata-hotel/dashboard/[applicationId].vue @@ -26,8 +26,8 @@ const completingParty = ref(undefined) onMounted(async () => { loading.value = true - const registrationId = route.params.registrationId as string - await loadStrata(registrationId) + const applicationId = route.params.applicationId as string + await loadStrata(applicationId) // set header stuff if (!permitDetails.value || !showPermitDetails.value) { // TODO: probably not ever going to get here? Filing would launch from the other account dashboard? @@ -48,11 +48,15 @@ onMounted(async () => { } ] if (!registration.value) { - setApplicationHeaderDetails( - isPaidApplication.value ? downloadApplicationReceipt : undefined, - application.value?.header.hostStatus) + setHeaderDetails( + application.value?.header.hostStatus, + undefined, + isPaidApplication.value ? downloadApplicationReceipt : undefined) } else { - setRegistrationHeaderDetails(permitDetails.value.status) + setHeaderDetails( + permitDetails.value.status, + permitDetails.value.expiryDate, + downloadApplicationReceipt) } // strata side details setSideHeaderDetails( @@ -127,7 +131,7 @@ setBreadcrumbs([
- +

diff --git a/strr-strata-web/app/pages/strata-hotel/dashboard/index.vue b/strr-strata-web/app/pages/strata-hotel/dashboard/index.vue index ca3af348..885eb10c 100644 --- a/strr-strata-web/app/pages/strata-hotel/dashboard/index.vue +++ b/strr-strata-web/app/pages/strata-hotel/dashboard/index.vue @@ -69,8 +69,7 @@ const { data: strataHotelList, status } = await useAsyncData( ) async function handleItemSelect (row: any) { - const identifier = row.id ?? row.number // id only exists in the registration objects - await navigateTo(localePath('/strata-hotel/dashboard/' + identifier)) + await navigateTo(localePath('/strata-hotel/dashboard/' + row.applicationNumber)) }