Skip to content

Action functions in To-do section #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ VUE_APP_POD_NAMESPACE="local"
VUE_APP_REGISTRY_URL="https://dev.bcros.ca/dashboard"
VUE_APP_REGISTRY_HOME_URL="https://dev.bcregistry.gov.bc.ca/"
VUE_APP_AUTH_WEB_URL="https://dev.account.bcregistry.gov.bc.ca/"
VUE_APP_BUSINESSES_URL="https://dev.account.bcregistry.gov.bc.ca/"
VUE_APP_BCONLINE_URL="https://d1.bconline.gov.bc.ca/"
VUE_APP_BUSINESS_EDIT_URL="https://dev.edit.business.bcregistry.gov.bc.ca"
VUE_APP_BUSINESS_CREATE_URL="https://dev.create.business.bcregistry.gov.bc.ca"
# old dashboard
VUE_APP_DASHBOARD_URL="https://dev.business.bcregistry.gov.bc.ca/"

Expand All @@ -19,7 +22,6 @@ VUE_APP_LEGAL_API_URL="https://legal-api-dev.apps.silver.devops.gov.bc.ca"
VUE_APP_LEGAL_API_VERSION_2="/api/v2"
VUE_APP_STATUS_API_URL="https://status-api-dev.apps.silver.devops.gov.bc.ca"
VUE_APP_STATUS_API_VERSION="/api/v1"
VUE_APP_BUSINESS_EDIT_URL="https://dev.edit.business.bcregistry.gov.bc.ca"

#vaults launchdarkly
# this is here to help CI pass and as this is already public it is OK to leave it here (dev value)
Expand Down
84 changes: 84 additions & 0 deletions cypress/e2e/components/todos/draft.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DraftFilingIncorporationApplicationNumbered } from '../../../fixtures/filings/draft/incorporation-applicaton'

context('TODOs -> Draft Filing', () => {
it('Test draft filing to-do item - base case (draft with no error)', () => {
cy.visitBusinessDashFor('businessInfo/ben/active.json', undefined, false, false, 'draft/changeOfRegistration.json')
Expand Down Expand Up @@ -107,4 +109,86 @@ context('TODOs -> Draft Filing', () => {
.contains('BC Registries is missing information about this business')
cy.get('[data-cy="todoItemActions-conversion"]').find('button').should('not.exist')
})

// Action: delete a draft
it('Delete Draft button is working)', () => {
cy.visitBusinessDashFor('businessInfo/ben/active.json', undefined, false, false, 'draft/changeOfRegistration.json')

cy.get('[data-cy="popover-button"]').click()
.get('[data-cy="menu-button-0"]').click()
.get('[data-cy="bcros-dialog-confirm"]').should('exist').as('dialog')

// click to delete the draft - when error: show error dialog and click to close
cy.intercept('DELETE', '**/businesses/*/filings/*', { statusCode: 401, body: {} }).as('deleteDraft')
.get('@dialog')
.find('[data-cy="bcros-dialog-btn"]')
.eq(0).click()
.wait('@deleteDraft')
.get('[data-cy="bcros-dialog-deleteError"]').should('exist').as('errorDialog')
.find('[data-cy="bcros-dialog-btn"]').should('exist').click()
.wait(1000)
.get('@errorDialog').should('not.exist')

// intercept the DELETE request and reload requests
cy.intercept('DELETE', '**/api/v2/businesses/*/filings/*', { statusCode: 200, body: {} }).as('deleteDraft')
cy.intercept('GET', '**/api/v2/businesses/**/tasks*').as('getTasks')
cy.intercept('GET', '**/api/v2/businesses/**/filings*').as('getFilings')

cy.get('[data-cy="popover-button"]').click()
.get('[data-cy="menu-button-0"]').click()
.get('[data-cy="bcros-dialog-confirm"]')
.find('[data-cy="bcros-dialog-btn"]')
.eq(0).click()
.wait('@deleteDraft')
.wait('@getTasks')
.wait('@getFilings')
})

// Action: resume - redirect to old dashboard
it('Resume a draft filing in the old dashboard', () => {
cy.visitBusinessDashFor('businessInfo/cp/active.json', undefined, false, false, 'draft/incompletePayment.json')
cy.fixture('todos/draft/incompletePayment.json').then((afrMockResponse) => {
const identifier = afrMockResponse.tasks[0].task.filing.business.identifier
const filingId = afrMockResponse.tasks[0].task.filing.header.filingId
const arYear = afrMockResponse.tasks[0].task.filing.header.ARFilingYear
cy.intercept('GET', '**/annual-report?**').as('getAnnualReportFiling')
cy.get('[data-cy^="todoItemActions-"]')
.click()
.wait('@getAnnualReportFiling')
.its('request.url')
.should('include', `/${identifier}/annual-report?accountid=1&filingId=${filingId}&arFilingYear=${arYear}`)
})
})

// Action: resume - redirect to create ui (dev.create.business.bcregistry.gov.bc.ca)
it('Resume a draft filing in Create UI', () => {
cy.visitTempBusinessDash(DraftFilingIncorporationApplicationNumbered, false)

const identifier = DraftFilingIncorporationApplicationNumbered.filing.business.identifier

// https://dev.create.business.bcregistry.gov.bc.ca/amalg-reg-information?accountid=3040&id=ThU9aP7BCV
cy.intercept('GET', '**/incorporation-define-company**').as('getIncorporationApplication')
cy.get('[data-cy^="todoItemActions-"]')
.click()
.wait('@getIncorporationApplication')
.its('request.url')
.should('include', '/incorporation-define-company')
.should('include', `id=${identifier}`)
})

// Action: resume - redirect to edit ui (dev.edit.business.bcregistry.gov.bc.ca)
it('Resume a draft filing in Edit UI', () => {
cy.visitBusinessDashFor('businessInfo/sp/active.json', undefined, false, false, 'draft/changeOfRegistration.json')
cy.fixture('todos/draft/changeOfRegistration.json').then((afrMockResponse) => {
const identifier = afrMockResponse.tasks[0].task.filing.business.identifier
const filingId = afrMockResponse.tasks[0].task.filing.header.filingId
cy.intercept('GET', '**/change/**').as('getChangeOfRegistrationFiling')
cy.get('[data-cy^="todoItemActions-"]')
.click()
.wait('@getChangeOfRegistrationFiling')
.its('request.url')
.should('include', `/${identifier}/change/`)
.should('include', `change-id=${filingId}`)
})
})
})
14 changes: 14 additions & 0 deletions cypress/e2e/components/todos/pending.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,18 @@ context('TODOs -> Pending Filing', () => {
.should('exist')
.should('have.text', 'Change Payment Type')
})

it('Cancel Payment button is working', () => {
cy.visitBusinessDashFor('businessInfo/ben/active.json', undefined, false, false, 'pendingPayment.json')

cy.get('[data-cy="popover-button"]').click()
.get('[data-cy="menu-button-0"]').click()
.get('[data-cy="bcros-dialog-confirm"]').should('exist').as('dialog')

// intercept the PATCH request and reload requests
cy.intercept('PATCH', '**/api/v2/businesses/*/filings/*', { statusCode: 200, body: {} }).as('cancelPayment')
cy.get('[data-cy="bcros-dialog-btn"]')
.eq(0).click()
.wait('@cancelPayment')
})
})
6 changes: 3 additions & 3 deletions cypress/fixtures/todos/draft/changeOfRegistration.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"filing": {
"business": {
"foundingDate": "2023-11-28T23:55:58.822929+00:00",
"identifier": "FM1060265",
"identifier": "FM1060270",
"legalName": "HRVOJE2 FEKETE2, HRVOJE FEKETE, et al",
"legalType": "GP"
},
"changeOfRegistration": {
"business": {
"identifier": "FM1060265"
"identifier": "FM1060270"
},
"contactPoint": {
"email": "hrvoje.fekete+gov.bc.test1@gmail.com",
Expand Down Expand Up @@ -185,4 +185,4 @@
}
}
]
}
}
2 changes: 2 additions & 0 deletions devops/vaults.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ VUE_APP_DASHBOARD_URL="op://web-url/$APP_ENV/business/DASHBOARD_URL"
VUE_APP_REGISTRY_URL="op://web-url/$APP_ENV/registry/REGISTRY_URL"
VUE_APP_REGISTRY_HOME_URL="op://web-url/$APP_ENV/registry/REGISTRY_HOME_URL"
VUE_APP_AUTH_WEB_URL="op://web-url/$APP_ENV/auth-web/AUTH_WEB_URL"
VUE_APP_BUSINESSES_URL="op://web-url/$APP_ENV/business/BUSINESSES_URL"
VUE_APP_BUSINESS_CREATE_URL="op://web-url/$APP_ENV/business-create/BUSINESS_CREATE_URL"

# vaults API
VUE_APP_PAY_API_URL="op://API/$APP_ENV/pay-api/PAY_API_URL"
Expand Down
2 changes: 2 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export default defineNuxtConfig({
addressCompleteKey: process.env.VUE_APP_ADDRESS_COMPLETE_KEY,
authApiURL: `${process.env.VUE_APP_AUTH_API_URL || ''}${process.env.VUE_APP_AUTH_API_VERSION || ''}`,
authWebURL: process.env.VUE_APP_AUTH_WEB_URL || '',
businessesURL: process.env.VUE_APP_BUSINESSES_URL || '',
dashboardOldUrl: process.env.VUE_APP_DASHBOARD_URL || '',
createURL: process.env.VUE_APP_BUSINESS_CREATE_URL || '',
kcURL: process.env.VUE_APP_KEYCLOAK_AUTH_URL || '',
kcRealm: process.env.VUE_APP_KEYCLOAK_REALM || '',
kcClient: process.env.VUE_APP_KEYCLOAK_CLIENTID || '',
Expand Down
86 changes: 63 additions & 23 deletions src/components/bcros/todo/Item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { filingTypeToName } from '~/utils/todo/task-filing/helper'

const t = useNuxtApp().$i18n.t
const todosStore = useBcrosTodos()
const business = useBcrosBusiness()
const { currentBusiness, currentBusinessIdentifier } = storeToRefs(useBcrosBusiness())
const { bootstrapIdentifier } = storeToRefs(useBcrosBusinessBootstrap())
const runtimeConfig = useRuntimeConfig()
const { redirect } = useBcrosNavigate()

const showConfirmDialog = ref(false)
const hasDeleteError = ref(false)
const hasCancelPaymentError = ref(false)
const confirmDialog = ref<DialogOptionsI | null>(null)

defineEmits(['expand'])
const emit = defineEmits(['expand', 'reload'])

const prop = defineProps({
item: { type: Object as PropType<TodoItemI>, required: true },
expanded: { type: Boolean, required: true }
Expand Down Expand Up @@ -77,7 +80,7 @@ const handleClick = (button: ActionButtonI) => {
}

if (button.openDialog) {
const businessId = business.currentBusinessIdentifier
const businessId = currentBusinessIdentifier.value

if (prop.item.status === FilingStatusE.DRAFT) {
// open the dialog for confirming deleting a draft filing (for existing businesses)
Expand Down Expand Up @@ -107,31 +110,68 @@ const useErrorStyle = (item: TodoItemI): boolean => {
}

/** Delete a draft; if refreshDashboard is set to true, refresh the page to reload data */
const deleteDraft = async (_refreshDashboard = true): Promise<void> => {
/* eslint-disable no-console */
console.log('Delete a draft')

// TO-DO: implement this function in ticket #22638; delete draft and handle errors
await Promise.resolve()
const deleteDraft = async (refreshDashboard = true): Promise<void> => {
const id = currentBusinessIdentifier.value || bootstrapIdentifier.value
const url = `${runtimeConfig.public.legalApiURL}/businesses/${id}/filings/${prop.item.filingId}`

await useBcrosFetch(url, { method: 'DELETE' }).then(({ error }) => {
showConfirmDialog.value = false
if (error.value) {
console.error('Error deleting a draft: ', error.value)
hasDeleteError.value = true
if (error.value.data.errors) { deleteErrors.value = error.value.data.errors }
if (error.value.data.warnings) { deleteWarnings.value = error.value.data.warnings }
} else if (refreshDashboard) {
emit('reload')
}
})
}

/** Delete an application draft and redirect */
const deleteApplication = async (): Promise<void> => {
await deleteDraft(false)

/* eslint-disable no-console */
console.log('Redirecting after deleting an application')
// TO-DO: implement this function in ticket #22638
// go to My Business Registry page if it is a name request
// otherwise go to BCROS home page
await deleteDraft(false).then(() => {
// do not redirect if there is an error,
// this logic does not exist in the old codebase.
if (hasDeleteError.value) { return }

// N.B.: in '.env.example', authWebURL and businessesURL are the same
if (prop.item.nameRequest) {
// go to My Business Registry page
redirect(runtimeConfig.public.authWebURL)
} else {
// go to BCROS home page
redirect(runtimeConfig.public.businessesURL)
}
})
}

/** Cancel the payment and set the filing status to draft; reload the page; handle errors if exist */
const cancelPaymentAndSetToDraft = async (_refreshDashboard = true): Promise<void> => {
/* eslint-disable no-console */
console.log('Cancel the payment and set the filing status to draft')
const url =
`${runtimeConfig.public.legalApiURL}/businesses/${currentBusinessIdentifier.value}/filings/${prop.item.filingId}`

await useBcrosFetch(url, { method: 'PATCH' }).then(({ error }) => {
showConfirmDialog.value = false
if (error.value) {
console.error('Error cancelling a payment: ', error.value)
hasCancelPaymentError.value = true
} else {
emit('reload')
}
})
}

/** Clear the error flag, errors and warning array for deleting a draft */
const clearDeleteErrors = (): void => {
hasDeleteError.value = false
deleteErrors.value = []
deleteWarnings.value = []
}

// TO-DO: implement this function in ticket #22638; delete draft and handle errors
await Promise.resolve()
/** Clear the error flag and errors array for cancelling a payment */
const clearCancelPaymentErrors = (): void => {
hasCancelPaymentError.value = false
cancelPaymentErrors.value = []
}
</script>

Expand All @@ -151,14 +191,14 @@ const cancelPaymentAndSetToDraft = async (_refreshDashboard = true): Promise<voi
:display="hasDeleteError"
:errors="deleteErrors"
:warnings="deleteWarnings"
@close="hasDeleteError = false"
@close="clearDeleteErrors()"
/>

<!-- error dialog (cancelling payment) -->
<BcrosTodoDialogCancelPaymentError
:display="hasCancelPaymentError"
:errors="cancelPaymentErrors"
@close="hasCancelPaymentError = false"
@close="clearCancelPaymentErrors()"
/>

<div
Expand Down Expand Up @@ -321,7 +361,7 @@ const cancelPaymentAndSetToDraft = async (_refreshDashboard = true): Promise<voi
>
<BcrosTodoExpansionContentAffiliation
v-if="item.expansionContent === TodoExpansionContentE.AFFILIATION_INVITATION"
:for-business-name="business.currentBusiness.legalName"
:for-business-name="currentBusiness.legalName"
:from-org-name="item.affiliationInvitationDetails?.fromOrgName"
:additional-message="item.affiliationInvitationDetails?.additionalMessage"
/>
Expand Down
3 changes: 3 additions & 0 deletions src/components/bcros/todo/List.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script setup lang="ts">
const t = useNuxtApp().$i18n.t

defineEmits(['reload'])

const todosStore = useBcrosTodos()

const prop = defineProps({
Expand Down Expand Up @@ -91,6 +93,7 @@ const expand = (index: number, expanded: boolean) => {
:class="index !== todos.length-1 ? 'border-b border-gray-400' : ''"
:expanded="isExpandedInternal[index] || false"
@expand="expand(index, $event)"
@reload="$emit('reload')"
/>
</template>
<div v-else class="flex flex-col justify-center items-center py-5 bg-white rounded">
Expand Down
31 changes: 23 additions & 8 deletions src/pages/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,33 @@ const containRole = (roleType) => {
party.roles.find(role => role.roleType === roleType && !role.cessationDate)
)
}
const loadBusinessInfo = async () => {
const loadBusinessInfo = async (force = false) => {
const identifier = route.params.identifier as string
if (identifier) {
if (bootstrap.checkIsTempReg(identifier)) {
// this is a business bootstrap (actual business does not exist yet)
await bootstrap.loadBusinessBootstrap(identifier)
await bootstrap.loadBusinessBootstrap(identifier, force)
useBcrosTodos().loadBootstrapTask({ enabled: true, order: 0, task: bootstrapFiling.value } as TaskI)
} else {
await business.loadBusiness(identifier)
business.loadBusinessAddresses(identifier)
business.loadParties(identifier)
useBcrosFilings().loadFilings(identifier)
await business.loadBusiness(identifier, force)
business.loadBusinessAddresses(identifier, force)
business.loadParties(identifier, force)
useBcrosFilings().loadFilings(identifier, force)
useBcrosTodos().loadAffiliations(identifier)
useBcrosTodos().loadTasks(identifier)
useBcrosTodos().loadTasks(identifier, true)
}
}
}

const reloadBusinessInfo = async () => {
useBcrosTodos().clearTodos()
useBcrosFilings().clearFilings()
// TO-DO: also need to clear the pending filing list (not yet implemented)

// reload business info using the force=true flag
await loadBusinessInfo(true)
}

onBeforeMount(async () => {
await loadBusinessInfo()
})
Expand Down Expand Up @@ -177,7 +186,13 @@ const pendingAddress = computed(() => {
<template #header>
{{ $t('title.section.toDo') }} <span class="font-normal">({{ todos.length }})</span>
</template>
<BcrosTodoList :todos="todos" class="bg-bcGovGray-100" />
<BcrosTodoList
:todos="todos"
class="bg-bcGovGray-100"
@reload="async () => {
await reloadBusinessInfo()
}"
/>
</BcrosSection>

<BcrosSection name="filingHistory">
Expand Down
Loading
Loading