From 198db8931a85d2e70a35eee4a43d7970eec7eb08 Mon Sep 17 00:00:00 2001 From: Rajandeep Date: Fri, 10 Jan 2025 08:58:55 -0800 Subject: [PATCH 01/16] Business Dashboard UI: implement background retry to check for latest state --- src/pages/dashboard.vue | 68 +++++++++++++++++++++++++++++++++++++++++ src/stores/business.ts | 24 ++++++++++++--- 2 files changed, 87 insertions(+), 5 deletions(-) diff --git a/src/pages/dashboard.vue b/src/pages/dashboard.vue index 7829f7fb..0ff9ee1d 100644 --- a/src/pages/dashboard.vue +++ b/src/pages/dashboard.vue @@ -18,6 +18,9 @@ const { todos } = storeToRefs(useBcrosTodos()) const { getPendingCoa } = useBcrosFilings() const { filings } = storeToRefs(useBcrosFilings()) const { pendingFilings } = storeToRefs(useBcrosBusinessBootstrap()) +const toast = useToast() +const finalDateString = ref(undefined) +const initialDateString = ref(undefined) const hasDirector = computed(() => { if (currentParties.value?.parties && currentParties.value?.parties.length > 0) { @@ -79,6 +82,66 @@ const containRole = (roleType) => { ) } +const computeTimeDifference = (initialDateString, finalDateString) => { + const initialDate = new Date(initialDateString) + const finalDate = new Date(finalDateString) + + const differenceInMilliseconds = finalDate - initialDate + return differenceInMilliseconds / 1000 +} + +const fetchBusinessDetailsWithDelay = async (identifier: string) => { + // Fetch business details and update finalDateString + const slimBusiness = await business.getBusinessDetails(identifier, undefined, true) + const finalDate = new Date(slimBusiness.lastModified) + finalDateString.value = finalDate.toISOString().split('.')[0] + + if (computeTimeDifference(business.initialDateString, finalDateString.value) > 0) { + toast.add({ + id: 'outdated_data', + title: 'Details on this page have been updated.', + description: 'Refresh to view the latest information.', + icon: 'i-octicon-desktop-download-24', + timeout: 0, + actions: [{ + label: 'Refresh', + click: () => { + reloadBusinessInfo() + } + }] + }) + } +} + +const startPolling = (identifier: string) => { + const startTime = Date.now() + + const firstInterval = 10000 + const secondInterval = 60000 + const thirdInterval = 3600000 + + const poll = () => { + const elapsedTime = Date.now() - startTime + + if (elapsedTime < 60000) { + // Poll every 10 seconds for the first minute + fetchBusinessDetailsWithDelay(identifier) + setTimeout(poll, firstInterval) + } else if (elapsedTime < 1800000) { + // Poll every 1 minute for the next 30 minutes + fetchBusinessDetailsWithDelay(identifier) + setTimeout(poll, secondInterval) + } else { + // Poll every 1 hour after 30 minutes + fetchBusinessDetailsWithDelay(identifier) + setTimeout(poll, thirdInterval) + } + } + + // Start the polling + poll() +} + // load information for the business or the bootstrap business, // and load the todo tasks, pending-review item, and filing history const loadBusinessInfo = async (force = false) => { @@ -108,6 +171,10 @@ const loadBusinessInfo = async (force = false) => { useBcrosTodos().loadAffiliations(identifier) useBcrosTodos().loadTasks(identifier, true) } + // assign initial value from /business + initialDateString.value = business.initialDateString + // start polling schedule + startPolling(identifier) } } @@ -249,6 +316,7 @@ const coaEffectiveDate = computed(() => { diff --git a/src/components/bcros/filing/addStaffFiling/modal/Form.vue b/src/components/bcros/filing/addStaffFiling/modal/Form.vue index a08e66a0..e03c09a0 100644 --- a/src/components/bcros/filing/addStaffFiling/modal/Form.vue +++ b/src/components/bcros/filing/addStaffFiling/modal/Form.vue @@ -7,7 +7,7 @@ const t = useNuxtApp().$i18n.t const filings = useBcrosFilings() const business = useBcrosBusiness() const { currentBusiness, currentBusinessName } = storeToRefs(business) -const emit = defineEmits(['close']) +const emit = defineEmits(['close', 'saved']) const prop = defineProps({ filingType: { type: String as () => FilingTypes, required: true } }) @@ -262,6 +262,7 @@ const submitFiling = async() => { // submit the filing upon successful validation const handleSubmit = () => { if (validate()) { + emit('saved') submitFiling() } } From 476ab3841e18bfad5f34c0e52d0558285fc865c8 Mon Sep 17 00:00:00 2001 From: Rajandeep Date: Thu, 16 Jan 2025 15:47:31 -0800 Subject: [PATCH 13/16] switched to wait for save before emiting event --- src/components/bcros/filing/addStaffFiling/modal/Form.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/bcros/filing/addStaffFiling/modal/Form.vue b/src/components/bcros/filing/addStaffFiling/modal/Form.vue index e03c09a0..6dce43d6 100644 --- a/src/components/bcros/filing/addStaffFiling/modal/Form.vue +++ b/src/components/bcros/filing/addStaffFiling/modal/Form.vue @@ -262,8 +262,8 @@ const submitFiling = async() => { // submit the filing upon successful validation const handleSubmit = () => { if (validate()) { - emit('saved') submitFiling() + emit('saved') } } From 7eef54fa5c5710352fb1621f5c9af8d6f51dfa6c Mon Sep 17 00:00:00 2001 From: Rajandeep Date: Thu, 16 Jan 2025 16:27:21 -0800 Subject: [PATCH 14/16] updated variables nd async calls --- .../bcros/filing/addStaffFiling/Index.vue | 18 +++++++++--------- src/pages/dashboard.vue | 12 +++++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/components/bcros/filing/addStaffFiling/Index.vue b/src/components/bcros/filing/addStaffFiling/Index.vue index dd2b27db..bfad45ce 100644 --- a/src/components/bcros/filing/addStaffFiling/Index.vue +++ b/src/components/bcros/filing/addStaffFiling/Index.vue @@ -22,10 +22,10 @@ const openCourtOrderModal = ref(false) const openDissolutionModal = ref(false) const openPutBackOnModal = ref(false) -const emit = defineEmits(['button-clicked']) +const emit = defineEmits(['saveLocalFilingEmit']) -const startPolling = () => { - emit('button-clicked') +const saveEmitForPolling = () => { + emit('saveLocalFilingEmit') } // Create a restoration filing and navigate to the appropriate page const restoreCompany = async (restorationType: FilingSubTypeE = null) => { @@ -185,37 +185,37 @@ const actions: ComputedRef>> = computed(() => { diff --git a/src/pages/dashboard.vue b/src/pages/dashboard.vue index 18391ccb..775a8896 100644 --- a/src/pages/dashboard.vue +++ b/src/pages/dashboard.vue @@ -170,11 +170,13 @@ const loadBusinessInfo = async (force = false) => { } } else { await business.loadBusiness(identifier, force) - business.loadBusinessAddresses(identifier, force) - business.loadParties(identifier, force) - useBcrosFilings().loadFilings(identifier, force) - useBcrosTodos().loadAffiliations(identifier) + await Promise.all([ + business.loadBusinessAddresses(identifier, force), + business.loadParties(identifier, force), + useBcrosFilings().loadFilings(identifier, force), + useBcrosTodos().loadAffiliations(identifier), useBcrosTodos().loadTasks(identifier, true) + ]) } // assign initial value from /business initialDateString.value = business.initialDateString @@ -415,7 +417,7 @@ const coaEffectiveDate = computed(() => { From 2893b2930b8bacd6b2b314105e641d385e2ecdcc Mon Sep 17 00:00:00 2001 From: Rajandeep Date: Thu, 16 Jan 2025 16:28:05 -0800 Subject: [PATCH 15/16] linting --- src/pages/dashboard.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/dashboard.vue b/src/pages/dashboard.vue index 775a8896..5e2dfc62 100644 --- a/src/pages/dashboard.vue +++ b/src/pages/dashboard.vue @@ -171,12 +171,12 @@ const loadBusinessInfo = async (force = false) => { } else { await business.loadBusiness(identifier, force) await Promise.all([ - business.loadBusinessAddresses(identifier, force), - business.loadParties(identifier, force), - useBcrosFilings().loadFilings(identifier, force), - useBcrosTodos().loadAffiliations(identifier), - useBcrosTodos().loadTasks(identifier, true) - ]) + business.loadBusinessAddresses(identifier, force), + business.loadParties(identifier, force), + useBcrosFilings().loadFilings(identifier, force), + useBcrosTodos().loadAffiliations(identifier), + useBcrosTodos().loadTasks(identifier, true) + ]) } // assign initial value from /business initialDateString.value = business.initialDateString @@ -417,7 +417,7 @@ const coaEffectiveDate = computed(() => { From cbc9b3a129593732e664103ba20d207e26fb9b31 Mon Sep 17 00:00:00 2001 From: Rajandeep Date: Fri, 17 Jan 2025 09:56:09 -0800 Subject: [PATCH 16/16] app version update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 66859101..3c285447 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "bcros-business-dashboard", "private": true, "type": "module", - "version": "1.0.4", + "version": "1.0.5", "scripts": { "build": "nuxt generate", "build:local": "nuxt build",