-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(members): divide profile, devices and capabilities into multiple…
… panels
Showing
10 changed files
with
453 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
src/views/Private/Members/Detail/MemberCapabilitesPanel.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<template> | ||
<form class="shadow sm:overflow-hidden sm:rounded-md" @submit.prevent="onSubmit"> | ||
<ul class="flex flex-col gap-4 bg-white px-4 py-5 sm:p-6"> | ||
<AppSwitchField | ||
as="li" | ||
:description="$t('members.detail.profile.capabilities.manager.description')" | ||
disabled | ||
:label="$t('members.detail.profile.capabilities.manager.label')" | ||
:model-value="member.isAdmin" /> | ||
<AppSwitchField | ||
v-model="state.canUnlockGate" | ||
as="li" | ||
:description="$t('members.detail.profile.capabilities.unlockGate.description')" | ||
:label="$t('members.detail.profile.capabilities.unlockGate.label')" | ||
:loading="isFetchingCapabilites" /> | ||
<AppSwitchField | ||
v-model="state.hasParkingAccess" | ||
as="li" | ||
:description="$t('members.detail.profile.capabilities.parkingAccess.description')" | ||
:label="$t('members.detail.profile.capabilities.parkingAccess.label')" | ||
:loading="isFetchingCapabilites" /> | ||
<AppSwitchField | ||
v-model="state.canUnlockDeckDoor" | ||
as="li" | ||
:description="$t('members.detail.profile.capabilities.unlockDeckDoor.description')" | ||
:label="$t('members.detail.profile.capabilities.unlockDeckDoor.label')" | ||
:loading="isFetchingCapabilites" /> | ||
<AppSwitchField | ||
v-model="state.hasKeysAccess" | ||
as="li" | ||
:description="$t('members.detail.profile.capabilities.keysAccess.description')" | ||
:label="$t('members.detail.profile.capabilities.keysAccess.label')" | ||
:loading="isFetchingCapabilites" /> | ||
<AppAlert | ||
v-if="capabilitiesError" | ||
:description="capabilitiesError.message" | ||
:title="$t('members.detail.profile.capabilities.onFetch.fail')" | ||
type="error"> | ||
<template #action> | ||
<AppButton | ||
class="self-start border border-gray-300 bg-white text-base text-gray-700 shadow-sm hover:bg-gray-50 focus:ring-gray-400 sm:w-auto sm:text-sm" | ||
:loading="isFetchingCapabilites" | ||
@click="refetchCapabilities"> | ||
{{ $t('action.retry') }} | ||
</AppButton> | ||
</template> | ||
</AppAlert> | ||
</ul> | ||
|
||
<div | ||
class="flex flex-row flex-wrap gap-3 border-t border-gray-200 bg-gray-50 px-4 py-3 sm:px-6"> | ||
<AppButton | ||
class="border border-transparent bg-indigo-600 text-white shadow-sm hover:bg-indigo-700 focus:ring-indigo-500" | ||
:icon="mdiCheckAll" | ||
:loading="state.isSubmitting" | ||
type="submit"> | ||
{{ $t('members.detail.profile.capabilities.apply') }} | ||
</AppButton> | ||
<AppAlert | ||
v-if="state.hasFailValidationOnce" | ||
class="truncate" | ||
:title=" | ||
$t('validations.invalidFields', { | ||
count: getVuelidateErrorFieldsCount(vuelidate.$errors), | ||
}) | ||
" | ||
:type="vuelidate.$errors.length > 0 ? 'error' : 'success'" /> | ||
</div> | ||
</form> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import AppAlert from '@/components/form/AppAlert.vue'; | ||
import AppButton from '@/components/form/AppButton.vue'; | ||
import AppSwitchField from '@/components/form/AppSwitchField.vue'; | ||
import { | ||
getVuelidateErrorFieldsCount, | ||
handleSilentError, | ||
scrollToFirstError, | ||
} from '@/helpers/errors'; | ||
import { UserCapabilities } from '@/services/api/auth'; | ||
import { Member, getMemberCapabilities, updateMemberCapabilities } from '@/services/api/members'; | ||
import { useNotificationsStore } from '@/store/notifications'; | ||
import { mdiCheckAll } from '@mdi/js'; | ||
import { useQuery, useQueryClient } from '@tanstack/vue-query'; | ||
import { useVuelidate } from '@vuelidate/core'; | ||
import { PropType, computed, nextTick, reactive, watch } from 'vue'; | ||
import { useI18n } from 'vue-i18n'; | ||
const emit = defineEmits(['update:member']); | ||
const props = defineProps({ | ||
member: { | ||
type: Object as PropType<Member>, | ||
required: true, | ||
}, | ||
}); | ||
const queryClient = useQueryClient(); | ||
const notificationsStore = useNotificationsStore(); | ||
const i18n = useI18n(); | ||
const state = reactive({ | ||
canUnlockGate: false as boolean, | ||
hasParkingAccess: false as boolean, | ||
canUnlockDeckDoor: false as boolean, | ||
hasKeysAccess: false as boolean, | ||
isSubmitting: false as boolean, | ||
hasFailValidationOnce: false as boolean, | ||
}); | ||
const { | ||
isFetching: isFetchingCapabilites, | ||
data: capabilities, | ||
error: capabilitiesError, | ||
refetch: refetchCapabilities, | ||
} = useQuery({ | ||
queryKey: ['members', computed(() => props.member._id), 'capabilities'], | ||
queryFn: ({ queryKey: [_, memberId] }) => getMemberCapabilities(memberId), | ||
retry: false, | ||
refetchOnWindowFocus: false, | ||
}); | ||
const rules = computed(() => ({})); | ||
const vuelidate = useVuelidate(rules, state); | ||
const onSubmit = async () => { | ||
const isValid = await vuelidate.value.$validate(); | ||
if (!isValid) { | ||
state.hasFailValidationOnce = true; | ||
nextTick(scrollToFirstError); | ||
return; | ||
} | ||
state.isSubmitting = true; | ||
(async () => { | ||
await updateMemberCapabilities(props.member._id, { | ||
[UserCapabilities.UNLOCK_GATE]: state.canUnlockGate, | ||
[UserCapabilities.PARKING_ACCESS]: state.hasParkingAccess, | ||
[UserCapabilities.UNLOCK_DECK_DOOR]: state.canUnlockDeckDoor, | ||
[UserCapabilities.KEYS_ACCESS]: state.hasKeysAccess, | ||
}); | ||
})() | ||
.then(() => { | ||
notificationsStore.addNotification({ | ||
message: i18n.t('members.detail.profile.capabilities.onUpdate.success', { | ||
name: [props.member.firstName, props.member.lastName].filter(Boolean).join(' '), | ||
}), | ||
type: 'success', | ||
timeout: 3_000, | ||
}); | ||
queryClient.invalidateQueries({ | ||
queryKey: ['members', computed(() => props.member._id), 'history'], | ||
}); | ||
}) | ||
.catch(handleSilentError) | ||
.catch((error) => { | ||
notificationsStore.addErrorNotification( | ||
error, | ||
i18n.t('members.detail.profile.capabilities.onUpdate.fail', { | ||
name: [props.member.firstName, props.member.lastName].filter(Boolean).join(' '), | ||
}), | ||
); | ||
return Promise.reject(error); | ||
}) | ||
.finally(() => { | ||
state.isSubmitting = false; | ||
}); | ||
}; | ||
watch( | ||
capabilities, | ||
(memberCapabilities) => { | ||
state.canUnlockGate = memberCapabilities?.[UserCapabilities.UNLOCK_GATE] ?? false; | ||
state.hasParkingAccess = memberCapabilities?.[UserCapabilities.PARKING_ACCESS] ?? false; | ||
state.canUnlockDeckDoor = memberCapabilities?.[UserCapabilities.UNLOCK_DECK_DOOR] ?? false; | ||
state.hasKeysAccess = memberCapabilities?.[UserCapabilities.KEYS_ACCESS] ?? false; | ||
}, | ||
{ immediate: true }, | ||
); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
src/views/Private/Members/Detail/MemberProfilePanel.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<template> | ||
<form class="shadow sm:overflow-hidden sm:rounded-md" @submit.prevent="onSubmit"> | ||
<div class="flex flex-col items-stretch bg-white px-4 pt-5 sm:px-6 sm:pt-6"> | ||
<div class="flex flex-row flex-wrap gap-x-6"> | ||
<AppTextField | ||
id="first-name" | ||
v-model="state.firstname" | ||
autocomplete="given-name" | ||
class="min-w-48 shrink grow basis-0" | ||
disabled | ||
:errors="vuelidate.firstname.$errors.map(({ $message }) => $message as string)" | ||
:label="$t('members.detail.profile.firstname.label')" | ||
name="first-name" | ||
required | ||
type="text" | ||
@blur="vuelidate.firstname.$touch()" /> | ||
<AppTextField | ||
id="last-name" | ||
v-model="state.lastname" | ||
autocomplete="family-name" | ||
class="min-w-48 shrink grow basis-0" | ||
disabled | ||
:errors="vuelidate.lastname.$errors.map(({ $message }) => $message as string)" | ||
:label="$t('members.detail.profile.lastname.label')" | ||
name="last-name" | ||
required | ||
type="text" | ||
@blur="vuelidate.lastname.$touch()" /> | ||
</div> | ||
|
||
<div class="flex flex-row flex-wrap gap-x-6"> | ||
<AppTextField | ||
id="email" | ||
v-model="state.email" | ||
autocomplete="email" | ||
class="min-w-48 shrink grow basis-0" | ||
disabled | ||
:errors="vuelidate.email.$errors.map(({ $message }) => $message as string)" | ||
:label="$t('members.detail.profile.email.label')" | ||
name="email" | ||
required | ||
type="email" | ||
@blur="vuelidate.email.$touch()" /> | ||
<AppTextField | ||
id="birthdate" | ||
v-model="state.birthdate" | ||
autocomplete="bday" | ||
class="min-w-48 shrink grow basis-0" | ||
disabled | ||
:label="$t('members.detail.profile.birthdate.label')" | ||
name="birthdate" | ||
:prepend-icon="mdiCakeVariantOutline" | ||
type="date" /> | ||
</div> | ||
</div> | ||
|
||
<div | ||
class="flex flex-row flex-wrap gap-3 border-t border-gray-200 bg-gray-50 px-4 py-3 sm:px-6"> | ||
<AppButton | ||
class="border border-transparent bg-indigo-600 text-white shadow-sm hover:bg-indigo-700 focus:ring-indigo-500" | ||
:icon="mdiCheckAll" | ||
:loading="state.isSubmitting" | ||
type="submit"> | ||
{{ $t('action.apply') }} | ||
</AppButton> | ||
<AppAlert | ||
v-if="state.hasFailValidationOnce" | ||
class="truncate" | ||
:title=" | ||
$t('validations.invalidFields', { | ||
count: getVuelidateErrorFieldsCount(vuelidate.$errors), | ||
}) | ||
" | ||
:type="vuelidate.$errors.length > 0 ? 'error' : 'success'" /> | ||
</div> | ||
</form> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import AppAlert from '@/components/form/AppAlert.vue'; | ||
import AppButton from '@/components/form/AppButton.vue'; | ||
import AppTextField from '@/components/form/AppTextField.vue'; | ||
import { | ||
handleSilentError, | ||
scrollToFirstError, | ||
getVuelidateErrorFieldsCount, | ||
} from '@/helpers/errors'; | ||
import { withAppI18nMessage } from '@/i18n'; | ||
import { Member, updateMember } from '@/services/api/members'; | ||
import { useNotificationsStore } from '@/store/notifications'; | ||
import { mdiCakeVariantOutline, mdiCheckAll } from '@mdi/js'; | ||
import { useQueryClient } from '@tanstack/vue-query'; | ||
import { useVuelidate } from '@vuelidate/core'; | ||
import { email, required } from '@vuelidate/validators'; | ||
import { PropType, computed, nextTick, reactive, watch } from 'vue'; | ||
import { useI18n } from 'vue-i18n'; | ||
const props = defineProps({ | ||
member: { | ||
type: Object as PropType<Member>, | ||
required: true, | ||
}, | ||
}); | ||
const queryClient = useQueryClient(); | ||
const notificationsStore = useNotificationsStore(); | ||
const i18n = useI18n(); | ||
const state = reactive({ | ||
firstname: null as string | null, | ||
lastname: null as string | null, | ||
email: null as string | null, | ||
birthdate: null as string | null, | ||
isSubmitting: false as boolean, | ||
hasFailValidationOnce: false as boolean, | ||
}); | ||
const rules = computed(() => ({ | ||
firstname: { | ||
// required: withAppI18nMessage(required) | ||
}, | ||
lastname: { | ||
// required: withAppI18nMessage(required) | ||
}, | ||
email: { | ||
required: withAppI18nMessage(required), | ||
email: withAppI18nMessage(email), | ||
}, | ||
})); | ||
const vuelidate = useVuelidate(rules, state); | ||
const onSubmit = async () => { | ||
const isValid = await vuelidate.value.$validate(); | ||
if (!isValid) { | ||
state.hasFailValidationOnce = true; | ||
nextTick(scrollToFirstError); | ||
return; | ||
} | ||
state.isSubmitting = true; | ||
(async () => { | ||
await updateMember(props.member._id, { | ||
firstName: state.firstname, | ||
lastName: state.lastname, | ||
email: state.email, | ||
birthdate: state.birthdate, | ||
} as never); | ||
})() | ||
.then(() => { | ||
notificationsStore.addNotification({ | ||
message: i18n.t('members.detail.profile.onUpdate.success', { | ||
name: [props.member.firstName, props.member.lastName].filter(Boolean).join(' '), | ||
}), | ||
type: 'success', | ||
timeout: 3_000, | ||
}); | ||
queryClient.invalidateQueries({ | ||
queryKey: ['members', computed(() => props.member._id), 'history'], | ||
}); | ||
}) | ||
.catch(handleSilentError) | ||
.catch((error) => { | ||
notificationsStore.addErrorNotification( | ||
error, | ||
i18n.t('members.detail.profile.onUpdate.fail', { | ||
name: [props.member.firstName, props.member.lastName].filter(Boolean).join(' '), | ||
}), | ||
); | ||
return Promise.reject(error); | ||
}) | ||
.finally(() => { | ||
state.isSubmitting = false; | ||
}); | ||
}; | ||
watch( | ||
() => props.member, | ||
(member) => { | ||
if (member) { | ||
state.firstname = member.firstName || null; | ||
state.lastname = member.lastName || null; | ||
state.email = member.email || null; | ||
state.birthdate = member.birthDate || null; | ||
} | ||
}, | ||
{ immediate: true }, | ||
); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters