Skip to content

Commit

Permalink
feat(FE:FSADT1-812): adding loading on details loading and global error
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Jun 29, 2023
1 parent d0e1c90 commit 1cfe372
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
22 changes: 20 additions & 2 deletions frontend/src/components/grouping/AddressGroupComponent.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { reactive, watch, computed, ref } from 'vue'
import { useEventBus } from '@vueuse/core'
import delete16 from '@carbon/icons-vue/es/trash-can/16'
import type { CodeNameType, BusinessSearchResult } from '@/core/CommonTypes'
import type { Address } from '@/dto/ApplyClientNumberDto'
Expand Down Expand Up @@ -31,12 +32,15 @@ const emit = defineEmits<{
(e: 'remove', value: number): void
}>()
const generalErrorBus = useEventBus<string>('general-error-notification')
//We set it as a separated ref due to props not being updatable
const selectedValue = reactive<Address>(props.modelValue)
const validateAddressData = props.validations[0]('Address', props.id + '')
const validateAddressNameData = props.validations[0]('Names', props.id + '')
const addressError = ref<string | undefined>('')
const nameError = ref<string | undefined>('')
const showDetailsLoading = ref<boolean>(false)
//Watch for changes on the input
watch([selectedValue], () => {
Expand Down Expand Up @@ -161,17 +165,27 @@ const autoCompleteUrl = computed(
`/api/clients/addresses?country=${selectedValue.country.value}&maxSuggestions=10&searchTerm=${selectedValue.streetAddress}`
)
const autoCompleteResult = ref<BusinessSearchResult>({} as BusinessSearchResult)
const detailsData = ref(null)
const detailsData = ref<Address | null>(null)
watch([autoCompleteResult], () => {
if (autoCompleteResult.value) {
const { error } = useFetchTo(
showDetailsLoading.value = true
const { error, loading: detailsLoading } = useFetchTo(
`/api/clients/addresses/${encodeURIComponent(
autoCompleteResult.value.code
)}`,
detailsData,
{}
)
watch([error], () => {
generalErrorBus.emit(error.value.response.data.message)
})
watch(
[detailsLoading],
() => (showDetailsLoading.value = detailsLoading.value)
)
}
})
Expand Down Expand Up @@ -246,6 +260,10 @@ watch([detailsData], () => {
validation.streetAddress = selectedValue.streetAddress ? true : false
"
/>
<div class="spinner-block" v-if="showDetailsLoading">
<bx-loading type="small"> </bx-loading>
<span>Loading address details...</span>
</div>
</data-fetcher>

<text-input-component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const emit = defineEmits<{
//Defining the event bus to send notifications up
const navigationBus = useEventBus<boolean>('navigation-notification')
const exitBus = useEventBus<Record<string, boolean | null>>('exit-notification')
const generalErrorBus = useEventBus<string>('general-error-notification')
//Set the prop as a ref, and then emit when it changes
const formData = ref<FormDataDto>(props.data)
Expand Down Expand Up @@ -119,12 +120,17 @@ watch([autoCompleteResult], () => {
showDetailsLoading.value = true
watch([error], () => {
if (error.value.response.status === 409) toggleErrorMessages(null, true)
if (error.value.response.status === 409) {
toggleErrorMessages(null, true)
return
}
if (error.value.response.status === 404) {
toggleErrorMessages(null, null)
validation.business = true
emit('update:data', formData.value)
return
}
generalErrorBus.emit(error.value.response.data.message)
})
watch(
Expand Down

0 comments on commit 1cfe372

Please sign in to comment.