Fixes some issues during edits of user profile

This commit is contained in:
2024-09-04 13:46:02 -04:00
parent eb9ed1f9a8
commit c2df527d4c
7 changed files with 65 additions and 32 deletions

View File

@@ -160,6 +160,21 @@ export const useUserStore = defineStore(
} }
} }
async function changePortrait(selectedFile) {
try {
const formData = new FormData();
formData.append('file', selectedFile)
const response = await client.post(
`/api/users/portrait`,
formData)
user.value.portraitUrl = `${response.data.blobUrl}?${Date.now()}` // the Date.now() is for cache-busting
} catch (error) {
console.error(error)
}
}
return { return {
user, user,
creator, creator,
@@ -173,6 +188,7 @@ export const useUserStore = defineStore(
changePhone, changePhone,
changeEmail, changeEmail,
changeAddress, changeAddress,
changePortrait,
fetchCurrentUserProfile, fetchCurrentUserProfile,
fetchCurrentCreatorProfile fetchCurrentCreatorProfile
} }

View File

@@ -18,12 +18,12 @@
<span class="value">Un portrait vous permet de personnaliser votre profil</span> <span class="value">Un portrait vous permet de personnaliser votre profil</span>
<span> <span>
<img <img
:src="userStore.portraitUrl" :src="userStore.user.portraitUrl"
alt="Profile Image" alt="Profile Image"
class="rounded-full" class="rounded-full"
width="48px" width="48px"
height="48px"> height="48px"/>
</span> </span>
</button> </button>
<button <button
@@ -94,6 +94,7 @@
<!-- Modal --> <!-- Modal -->
<v-dialog v-model="dialogEditPortraitShown" max-width="600px"> <v-dialog v-model="dialogEditPortraitShown" max-width="600px">
<portrait-dialog <portrait-dialog
:portrait-url="userStore.user.portraitUrl"
@close="handleCloseEditPortrait" @close="handleCloseEditPortrait"
@save="handleSaveEditPortrait" @save="handleSaveEditPortrait"
></portrait-dialog> ></portrait-dialog>
@@ -101,6 +102,8 @@
<v-dialog v-model="dialogEditFullnameShown" max-width="600px"> <v-dialog v-model="dialogEditFullnameShown" max-width="600px">
<fullname-dialog <fullname-dialog
:firstname="userStore.user.firstname"
:lastname="userStore.user.lastname"
@close="handleCloseEditFullname" @close="handleCloseEditFullname"
@save="handleSaveEditFullname" @save="handleSaveEditFullname"
></fullname-dialog> ></fullname-dialog>
@@ -108,6 +111,7 @@
<v-dialog v-model="dialogEditAliasShown" max-width="600px"> <v-dialog v-model="dialogEditAliasShown" max-width="600px">
<alias-dialog <alias-dialog
:alias="userStore.user.alias"
@close="handleCloseEditAlias" @close="handleCloseEditAlias"
@save="handleSaveEditAlias" @save="handleSaveEditAlias"
></alias-dialog> ></alias-dialog>
@@ -115,6 +119,7 @@
<v-dialog v-model="dialogEditBirthdayShown" max-width="600px"> <v-dialog v-model="dialogEditBirthdayShown" max-width="600px">
<birthday-dialog <birthday-dialog
:birth-date="userStore.user.birthDate"
@close="handleCloseEditBirthday" @close="handleCloseEditBirthday"
@save="handleSaveEditBirthday" @save="handleSaveEditBirthday"
></birthday-dialog> ></birthday-dialog>
@@ -122,6 +127,7 @@
<v-dialog v-model="dialogEditPhoneShown" max-width="600px"> <v-dialog v-model="dialogEditPhoneShown" max-width="600px">
<phone-dialog <phone-dialog
:phone="userStore.user.phoneNumber"
@close="handleCloseEditPhone" @close="handleCloseEditPhone"
@save="handleSaveEditPhone" @save="handleSaveEditPhone"
></phone-dialog> ></phone-dialog>
@@ -129,6 +135,7 @@
<v-dialog v-model="dialogEditEmailShown" max-width="600px"> <v-dialog v-model="dialogEditEmailShown" max-width="600px">
<email-dialog <email-dialog
:email="userStore.user.email"
@close="handleCloseEditEmail" @close="handleCloseEditEmail"
@save="handleSaveEditEmail" @save="handleSaveEditEmail"
></email-dialog> ></email-dialog>
@@ -136,11 +143,11 @@
<v-dialog v-model="dialogEditAddressShown" max-width="600px"> <v-dialog v-model="dialogEditAddressShown" max-width="600px">
<address-dialog <address-dialog
:address="userStore.user.address"
@close="handleCloseEditAddress" @close="handleCloseEditAddress"
@save="handleSaveEditAddress" @save="handleSaveEditAddress"
></address-dialog> ></address-dialog>
</v-dialog> </v-dialog>
</template> </template>
<script setup> <script setup>
@@ -168,8 +175,8 @@ function handleCloseEditPortrait() {
dialogEditPortraitShown.value = false dialogEditPortraitShown.value = false
} }
function handleSaveEditPortrait(portraitUrl) { function handleSaveEditPortrait(portraitData) {
console.log(`going to save portrait: ${portraitUrl}`) userStore.changePortrait(portraitData)
dialogEditPortraitShown.value = false dialogEditPortraitShown.value = false
} }
@@ -273,11 +280,9 @@ function handleSaveEditAddress(address) {
userStore.changeAddress(address) userStore.changeAddress(address)
dialogEditAddressShown.value = false dialogEditAddressShown.value = false
} }
</script> </script>
<style> <style>
.editableValue { .editableValue {
@apply py-2 px-4 border-gray-400 shadow flex items-center transition duration-200 ease-in-out w-full; @apply py-2 px-4 border-gray-400 shadow flex items-center transition duration-200 ease-in-out w-full;
@apply hover:bg-[#A6147D] hover:text-white hover:opacity-90; @apply hover:bg-[#A6147D] hover:text-white hover:opacity-90;
@@ -290,5 +295,4 @@ function handleSaveEditAddress(address) {
.value { .value {
@apply flex-auto pr-6 text-left; @apply flex-auto pr-6 text-left;
} }
</style> </style>

View File

@@ -29,14 +29,8 @@ import {ref} from 'vue';
const props = defineProps(['address']) const props = defineProps(['address'])
const emit = defineEmits(['close', 'save']) const emit = defineEmits(['close', 'save'])
const title = ref(props.title);
const address = ref(props.address); const address = ref(props.address);
const requestClose = () => emit('close') const requestClose = () => emit('close')
const requestSave = () => emit('save', address.value) const requestSave = () => emit('save', address.value)
</script> </script>
<style scoped>
</style>

View File

@@ -23,7 +23,6 @@
</v-card> </v-card>
</template> </template>
<script setup> <script setup>
import {ref} from 'vue'; import {ref} from 'vue';

View File

@@ -1,5 +1,4 @@
<template> <template>
<v-card> <v-card>
<v-card-title> <v-card-title>
Numéro de téléphone Numéro de téléphone
@@ -23,7 +22,6 @@
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</template> </template>
<script setup> <script setup>
@@ -32,7 +30,7 @@ import {ref} from 'vue';
const props = defineProps(['phone']) const props = defineProps(['phone'])
const emit = defineEmits(['close', 'save']) const emit = defineEmits(['close', 'save'])
const phone = ref(props.email) const phone = ref(props.phone)
const requestClose = () => emit('close') const requestClose = () => emit('close')
const requestSave = () => emit('save', phone.value) const requestSave = () => emit('save', phone.value)

View File

@@ -5,10 +5,19 @@
</v-card-title> </v-card-title>
<div class="m-4"> <div class="m-4">
<v-text-field <img
:src="portraitData"
class="mb-5 w-full transition duration-200 ease-in-out transform"
alt="Aperçu de la bannière"
/>
<v-file-input
@change="onSelectedFileChanged"
v-model="selectedFile"
variant="outlined" variant="outlined"
v-model="portraitUrl" accept="image/*"
></v-text-field> label="Votre bannière"
></v-file-input>
</div> </div>
<v-card-actions> <v-card-actions>
@@ -29,8 +38,21 @@ import {ref} from 'vue';
const props = defineProps(['portraitUrl']) const props = defineProps(['portraitUrl'])
const emit = defineEmits(['close', 'save']) const emit = defineEmits(['close', 'save'])
const portraitUrl = ref(props.portraitUrl) const portraitData = ref(props.portraitUrl)
const selectedFile = ref({})
const onSelectedFileChanged = () => {
if (selectedFile.value) {
const reader = new FileReader()
reader.onload = (event) => {
portraitData.value = event.target.result
}
reader.readAsDataURL(selectedFile.value)
} else {
portraitData.value = null
}
}
const requestClose = () => emit('close') const requestClose = () => emit('close')
const requestSave = () => emit('save', portraitUrl.value) const requestSave = () => emit('save', selectedFile.value)
</script> </script>

View File

@@ -36,7 +36,7 @@ const props = defineProps({
const emits = defineEmits(['closeRequested']) const emits = defineEmits(['closeRequested'])
const selectedFile = ref("") const selectedFile = ref({})
const fileUrl = ref(props.creator.images.banner) const fileUrl = ref(props.creator.images.banner)
const onFileSelected = () => { const onFileSelected = () => {