Skip to content

Commit

Permalink
UI - strata hotel application (#274)
Browse files Browse the repository at this point in the history
* UI - strata hotel application

Signed-off-by: Kial Jinnah <[email protected]>

* updated address usage for base web changes

Signed-off-by: Kial Jinnah <[email protected]>

* Final initial strata form updates

Signed-off-by: Kial Jinnah <[email protected]>

* PR comment

Signed-off-by: Kial Jinnah <[email protected]>

---------

Signed-off-by: Kial Jinnah <[email protected]>
  • Loading branch information
kialj876 authored Nov 6, 2024
1 parent d54fad8 commit 9e75c9c
Show file tree
Hide file tree
Showing 24 changed files with 1,013 additions and 135 deletions.
18 changes: 13 additions & 5 deletions strr-base-web/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
export default defineAppConfig({
strrBaseLayer: {
page: {
Expand Down Expand Up @@ -25,12 +26,14 @@ export default defineAppConfig({
base: 'file:text-gray-700 file:pt-2'
},
color: {
gray: {
outline: 'bg-gray-100 ring-0 disabled:hover:bg-gray-100 disabled:hover:border-gray-500 hover:bg-gray-200 hover:border-gray-600 focus:border-primary-500 focus:border-b-2 focus:ring-0'
},
red: {
outline: 'bg-red-100 ring-0 border-red-600 placeholder-red-600 hover:bg-gray-200 ' +
'focus:border-red-600 focus:border-b-2 focus:ring-0'
outline: 'bg-red-100 ring-0 border-red-600 placeholder-red-600 focus:border-red-600 focus:border-b-2 focus:ring-0'
},
primary: {
outline: 'bg-primary-50 ring-0 border-primary-500 hover:bg-gray-200 focus:border-b-2 focus:ring-0'
outline: 'bg-primary-50 ring-0 border-primary-500 focus:border-b-2 focus:ring-0'
}
}
},
Expand All @@ -39,9 +42,14 @@ export default defineAppConfig({
},
select: {
color: {
gray: {
outline: 'bg-gray-100 ring-0 disabled:hover:bg-gray-100 hover:bg-gray-200 hover:border-gray-600 focus:border-primary-500 focus:border-b-2 focus:ring-0'
},
primary: {
outline: 'bg-primary-50 ring-0 border-primary-500 disabled:hover:bg-primary-50 focus:border-b-2 focus:ring-0'
},
red: {
outline: 'bg-red-100 border-red-600 ring-0 hover:bg-gray-200 ' +
'focus:border-red-600 focus:border-b-2 focus:ring-0'
outline: 'bg-red-100 border-red-600 ring-0 focus:border-red-600 focus:border-b-2 focus:ring-0'
}
}
},
Expand Down
54 changes: 46 additions & 8 deletions strr-base-web/app/components/connect/form/address/Index.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import type { Form } from '#ui/types'
const country = defineModel<string>('country')
const street = defineModel<string>('street')
const streetAdditional = defineModel<string>('streetAdditional')
Expand All @@ -10,20 +12,17 @@ const locationDescription = defineModel<string>('locationDescription')
type AddressField = 'country' | 'street' | 'streetAdditional' | 'city' |
'region' | 'postalCode' | 'locationDescription'
const {
id,
enableAddressComplete,
schemaPrefix,
disabledFields
} = defineProps<{
const props = defineProps<{
id: string,
enableAddressComplete:(id: string, countryIso2: string, countrySelect: boolean) => void,
schemaPrefix: string,
formRef?: Form<any>,
disabledFields?: AddressField[],
excludedFields?: AddressField[],
locationDescLabel?: boolean
}>()
const { address: canadaPostAddress, enableAddressComplete } = useCanadaPostAddress()
const countries = iscCountriesListSortedByName
const regions = computed(() => {
switch (country.value) {
Expand All @@ -38,10 +37,49 @@ const regions = computed(() => {
const addressComplete = () => {
if (typeof country.value === 'string') {
enableAddressComplete(id, country.value, !disabledFields?.includes('country'))
enableAddressComplete(props.id, country.value, !props.disabledFields?.includes('country'))
}
}
watch(canadaPostAddress, (newAddress) => {
// automatically populate all non excluded / non disabled fields
if (newAddress) {
// clear form validation for city/region/postalCode if address is autocompleted
if (props.formRef) {
props.formRef.clear(`${props.schemaPrefix}country`)
props.formRef.clear(`${props.schemaPrefix}city`)
props.formRef.clear(`${props.schemaPrefix}region`)
props.formRef.clear(`${props.schemaPrefix}postalCode`)
}
for (const key of Object.keys(newAddress)) {
if (
!props.disabledFields?.includes(key as AddressField) &&
!props.excludedFields?.includes(key as AddressField)
) {
switch (key as AddressField) {
case 'street':
street.value = newAddress.street
break
case 'streetAdditional':
streetAdditional.value = newAddress.streetAdditional
break
case 'country':
country.value = newAddress.country
break
case 'city':
city.value = newAddress.city
break
case 'region':
region.value = newAddress.region
break
case 'postalCode':
postalCode.value = newAddress.postalCode
}
}
}
}
})
const addId = useId()
</script>
<template>
Expand Down
2 changes: 1 addition & 1 deletion strr-base-web/app/components/connect/form/field/Group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type UseEventBusReturn } from '@vueuse/core'
const formBus = inject<UseEventBusReturn<any, string> | undefined>('form-events', undefined)
const model = defineModel({ type: String, default: '' })
const model = defineModel<string | number>()
watch(model, () => {
formBus?.emit({ type: 'blur', path: props.name })
formBus?.emit({ type: 'change', path: props.name })
Expand Down
11 changes: 2 additions & 9 deletions strr-base-web/app/components/connect/form/field/Index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<script setup lang="ts">
import { normalizeInput } from '~/utils/connect-validation'
const model = defineModel({ type: String, default: '' })
const model = defineModel<string | number>()
defineProps({
id: { type: String, required: true },
Expand All @@ -16,16 +14,12 @@ defineProps({
ariaLabel: { type: String, default: undefined },
type: { type: String, default: 'text' }
})
const normalize = () => {
model.value = normalizeInput(model.value)
}
</script>

<template>
<UInput
:id="id"
v-model="model"
v-model.trim="model"
v-bind="$attrs"
:type
class="max-w-bcGovInput"
Expand All @@ -38,7 +32,6 @@ const normalize = () => {
:aria-invalid="isInvalid"
:aria-describedby="helpId"
:aria-label="ariaLabel"
@blur="normalize"
/>
<!-- :aria-errormessage="errorId" -->
<!-- Doesnt look like aria-errormessage is well supported, need to look into this more -->
Expand Down
7 changes: 4 additions & 3 deletions strr-base-web/app/composables/useCanadaPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export const useCanadaPostAddress = () => {
locationDescription: ''
})

const createAddressComplete = (pca: any, key: string, id: string, countryIso2: string,
countrySelect: boolean): object => {
const createAddressComplete = (
pca: any, key: string, id: string, countryIso2: string, countrySelect: boolean
): object => {
const fields = [
{ element: id, field: 'Line1', mode: pca.fieldMode.SEARCH }
]
Expand All @@ -34,7 +35,7 @@ export const useCanadaPostAddress = () => {
activeAddressField.value = id
const config = useRuntimeConfig()
const pca = (window as any).pca
const key = config.public.addressCompleteKey
const key = config.public.addressCompleteKey as string
if (!pca || !key) {
console.warn('AddressComplete not initialized due to missing script and/or key')
return
Expand Down
4 changes: 2 additions & 2 deletions strr-base-web/app/composables/useStrrApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const useStrrApi = () => {
return resp.applications
}

const postApplication = async <T extends { registration: ApiBaseRegistration }>(body: T) => {
return await $strrApi<T>('/applications', {
const postApplication = async <T extends { registration: ApiBaseRegistration }, R extends T>(body: T) => {
return await $strrApi<R>('/applications', {
method: 'POST',
body
})
Expand Down
1 change: 1 addition & 0 deletions strr-base-web/app/locales/en-CA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export default {
last: 'Please enter a last name',
full: 'Please enter a full legal name'
},
number: 'Please enter a number',
phone: {
code: 'Please select a country code',
number: 'Please enter a phone number'
Expand Down
13 changes: 0 additions & 13 deletions strr-base-web/app/utils/connect-validation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ export const getRequiredNonEmptyString = (message: string) => z.string().refine(
export const getRequiredUrl = (message: string) =>
z.string().refine(e => e.trim() !== '' && httpRegex.test(e), message)

/**
* Normalizes a string.
* If the input is provided, it removes leading, trailing, and extra spaces within the name.
* If the input is undefined, it returns an empty string.
* @param {string | undefined} input - the input to normalize.
*/
export const normalizeInput = (input?: string): string => {
if (input === undefined) {
return ''
}
return input.trim().replace(/\s+/g, ' ')
}

export const checkSpecialCharacters = (input: string | undefined): boolean => {
return input === undefined || /^[\d\s]*$/.test(input)
}
41 changes: 2 additions & 39 deletions strr-platform-web/app/components/form/platform/BusinessDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,43 +66,6 @@ watch(() => platformBusiness.value.hasRegOffAtt,
}
)
// address stuff
const {
activeAddressField,
address: canadaPostAddress,
enableAddressComplete
} = useCanadaPostAddress()
const activeAddressPath = computed(() => {
if (activeAddressField.value === 'platform-business-address') {
return 'mailingAddress'
}
return 'regOfficeOrAtt.mailingAddress'
})
watch(canadaPostAddress, (newAddress) => {
if (platformBusinessFormRef.value) {
// reset form validation for city/region/postalCode if address is changed
platformBusinessFormRef.value.clear(`${activeAddressPath.value}.city`)
platformBusinessFormRef.value.clear(`${activeAddressPath.value}.region`)
platformBusinessFormRef.value.clear(`${activeAddressPath.value}.postalCode`)
if (newAddress && activeAddressPath.value === 'mailingAddress') {
platformBusiness.value.mailingAddress.street = newAddress.street
platformBusiness.value.mailingAddress.streetAdditional = newAddress.streetAdditional
platformBusiness.value.mailingAddress.country = newAddress.country
platformBusiness.value.mailingAddress.city = newAddress.city
platformBusiness.value.mailingAddress.region = newAddress.region
platformBusiness.value.mailingAddress.postalCode = newAddress.postalCode
} else if (newAddress) {
// NOTE: country and region are not set because they are disabled for regOfficeOrAtt.mailingAddress
platformBusiness.value.regOfficeOrAtt.mailingAddress.street = newAddress.street
platformBusiness.value.regOfficeOrAtt.mailingAddress.streetAdditional = newAddress.streetAdditional
platformBusiness.value.regOfficeOrAtt.mailingAddress.city = newAddress.city
platformBusiness.value.regOfficeOrAtt.mailingAddress.postalCode = newAddress.postalCode
}
}
})
onMounted(async () => {
// validate form if step marked as complete
if (props.isComplete) {
Expand Down Expand Up @@ -202,7 +165,7 @@ onMounted(async () => {
v-model:region="platformBusiness.mailingAddress.region"
v-model:postal-code="platformBusiness.mailingAddress.postalCode"
:schema-prefix="'mailingAddress.'"
:enable-address-complete="enableAddressComplete"
:form-ref="platformBusinessFormRef"
/>
</div>
</ConnectFormSection>
Expand Down Expand Up @@ -258,8 +221,8 @@ onMounted(async () => {
v-model:region="platformBusiness.regOfficeOrAtt.mailingAddress.region"
v-model:postal-code="platformBusiness.regOfficeOrAtt.mailingAddress.postalCode"
:schema-prefix="'regOfficeOrAtt.mailingAddress.'"
:enable-address-complete="enableAddressComplete"
:disabled-fields="['country', 'region']"
:form-ref="platformBusinessFormRef"
/>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion strr-platform-web/app/locales/en-CA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export default {
subTitle: {
brand: 'Platform Brand',
noticeNonCompliance: 'Notice of Non-Compliance',
regOfficeAttSvcAddrress: 'Registered Office or Attorney for Service Address',
size: 'Platform Size',
takedownRequest: 'Takedown Request'
}
Expand Down
2 changes: 1 addition & 1 deletion strr-platform-web/app/stores/platformApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const useStrrPlatformApplication = defineStore('strr/platformApplication'

console.info('submitting application: ', body)

return await postApplication<PlatformApplicationPayload>(body)
return await postApplication<PlatformApplicationPayload, PlatformApplicationResp>(body)
}

return {
Expand Down
3 changes: 2 additions & 1 deletion strr-platform-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@daxiom/nuxt-core-layer-test": "^0.0.10",
"@vuepic/vue-datepicker": "^9.0.3",
"country-codes-list": "^1.6.11",
"nuxt": "^3.12.3"
"nuxt": "^3.12.3",
"vue-country-flag-next": "^2.3.2"
}
}
12 changes: 12 additions & 0 deletions strr-platform-web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9e75c9c

Please sign in to comment.