feat: Add creator profile and about section improvements

This commit is contained in:
2025-04-22 15:35:08 -04:00
parent 9c88b18f60
commit 524b429170
9 changed files with 1007 additions and 730 deletions

View File

@@ -1,627 +1,92 @@
<template>
<div class="p-4">
<div v-if="creatorProfileStore.creator?.id === brandingStore.value.id"
class="flex justify-end">
<div class="creator-home">
<!-- Content sections container -->
<div class="content-sections">
<!-- Bouton principal : Éditer ou Enregistrer -->
<button
v-if="isLoggedIn"
class="primary"
@click="isEditMode ? saveChanges() : toggleEditMode()"
>
{{ isEditMode ? t('common.save') : t('common.edit') }}
</button>
<button
v-if="isEditMode && isLoggedIn"
class="secondary"
@click="cancelEdit"
>
{{ t('common.cancel') }}
</button>
</div>
<!-- MainPage -->
<div class="flex flex-col mt-4">
<h1 class="flex justify-start text-2xl font-bold text-center mb-4">{{ t('creator.sections.about.title') }}</h1>
<div>
<!-- Main image Bloc D'information-->
<div class="py-4">
<div v-if="!isEditMode">
<p v-if="mainImageText" class="text-lg text-justify">
{{ mainImageText }}
</p>
</div>
<v-textarea v-if="isEditMode" v-model="editableMainImageText" class="w-full p-2 py-6 " :label="t('creator.sections.about.description')"
variant="outlined"></v-textarea>
<div class="flex flex-row items-center space-x-4">
<!-- image principale-->
<div v-if="!isEditMode" class="flex justify-center items-center w-1/2">
<img
v-if="mainImageUrl"
:src="mainImageUrl"
:alt="t('creator.sections.about.mainImage')"
class="max-w-full h-auto cursor-pointer"/>
</div>
<div v-if="isEditMode" class="relative flex justify-center">
<label>
<input class="hidden" type="file" @change="updateImage('mainImageUrl', $event)"/>
<img :src="mainImageUrl || fallbackImage"
:alt="t('creator.sections.about.mainImage')"
class=" max-w-full h-auto cursor-pointer max-h-96"/>
</label>
<button v-if="isEditMode"
class="absolute top-10 right-2 px-2 py-1 bg-red-500 text-white hover:bg-red-600"
@click="deleteImage('mainImageUrl')">
{{ t('common.delete') }}
</button>
</div>
<div class="w-1/2 flex flex-col justify-center">
<h2 v-if="videoSubtitleMain" class="text-xl font-semibold text-center">
{{ t('creator.sections.support.title') }}
</h2>
<div v-if="!isEditMode">
<p v-if="mainVideoText" class="text-lg text-justify">
{{ mainVideoText }}
</p>
</div>
<div v-if="isEditMode">
<v-textarea
v-model="editableMainVideoText"
class="p-2 rounded-md mt-4"
:label="t('creator.sections.support.description')"
rows="10"
variant="outlined"
></v-textarea>
</div>
</div>
</div>
<div>
<div v-if="!isEditMode" class="py-5 text-lg font-bold">
{{ videoSubtitle }}
</div>
<div v-if="isEditMode">
<v-text-field
v-model="editableVideoSubtitle"
class="w-full p-2"
:label="t('creator.sections.support.subtitle')"
variant="outlined"
></v-text-field>
</div>
<v-textarea v-if="isEditMode"
v-model="editableVideoText"
class="w-full p-2"
:label="t('creator.sections.support.description')"
variant="outlined"
></v-textarea>
</div>
</div>
<!-- media-->
<div v-if="!isEditMode">
<div v-if="videoUrlMain" class="video-container">
<iframe
:src="videoUrlMain"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
class="video-frame"
title="YouTube video player">
</iframe>
</div>
</div>
<div v-if="isEditMode">
<v-text-field
v-model="editableVideoUrlMain"
class="w-full p-2 rounded-md"
:label="t('creator.fields.videoUrl')"
type="text"
variant="outlined"
/>
</div>
<!-- Images -->
<div v-if="!isEditMode">
<div v-if="imagesSubtitle || image1Url || image2Url || image3Url || image4Url || imagesText ">
<!-- images-->
<div class="py-2">
<div>
<!-- Affichage des images -->
<div class="flex gap-2">
<!-- Première image -->
<div v-if="image1Url" class="relative w-full sm:flex-1 ">
<img :src="image1Url"
:alt="t('creator.sections.about.image1')"
class="rounded-md max-w-full h-auto cursor-pointer"/>
</div>
<!-- Deuxième image -->
<div v-if="image2Url" class="relative w-full sm:flex-1 ">
<img :src="image2Url"
:alt="t('creator.sections.about.image2')"
class="rounded-md max-w-full h-auto cursor-pointer"/>
</div>
<!-- Troisième image -->
<div v-if="image3Url" class="relative w-full sm:flex-1 ">
<img :src="image3Url"
:alt="t('creator.sections.about.image3')"
class="rounded-md max-w-full h-auto cursor-pointer"/>
</div>
<!-- Quatrième image -->
<div v-if="image4Url" class="relative w-full sm:flex-1 ">
<img :src="image4Url"
:alt="t('creator.sections.about.image4')"
class="rounded-md max-w-full h-auto cursor-pointer"/>
</div>
</div>
</div>
</div>
</div>
</div>
<div v-if="isEditMode" class="rounded-2xl">
<!--images-->
<div class=" text-2xl pa-2">{{ t('creator.sections.about.images') }}</div>
<div class="pa-2 grid grid-cols-1 gap-4 md:grid-cols-4">
<!-- Première image -->
<div class="relative">
<label>
<input class="hidden" type="file" @change="updateImage('image1Url', $event)"/>
<img :src="image1Url || fallbackImage"
:alt="t('creator.sections.about.image1')"
class="rounded-md max-w-full h-auto cursor-pointer"/>
</label>
<button class="absolute top-2 right-2 px-2 py-1 bg-red-500 text-white hover:bg-red-600"
@click="deleteImage('image1Url')">
{{ t('common.delete') }}
</button>
</div>
<!-- Deuxième image -->
<div class="relative">
<label>
<input class="hidden" type="file" @change="updateImage('image2Url', $event)"/>
<img :src="image2Url || fallbackImage"
:alt="t('creator.sections.about.image2')"
class="rounded-md max-w-full h-auto cursor-pointer"/>
</label>
<button class="absolute top-2 right-2 px-2 py-1 bg-red-500 text-white hover:bg-red-600"
@click="deleteImage('image2Url')">
{{ t('common.delete') }}
</button>
</div>
<!-- Troisième image -->
<div class="relative">
<label>
<input class="hidden" type="file" @change="updateImage('image3Url', $event)"/>
<img :src="image3Url || fallbackImage"
:alt="t('creator.sections.about.image3')"
class="rounded-md max-w-full h-auto cursor-pointer"/>
</label>
<button class="absolute top-2 right-2 px-2 py-1 bg-red-500 text-white hover:bg-red-600"
@click="deleteImage('image3Url')">
{{ t('common.delete') }}
</button>
</div>
<!-- Quatrième image -->
<div class="relative">
<label>
<input class="hidden" type="file" @change="updateImage('image4Url', $event)"/>
<img :src="image4Url || fallbackImage"
:alt="t('creator.sections.about.image4')"
class="rounded-md max-w-full h-auto cursor-pointer"/>
</label>
<button class="absolute top-2 right-2 px-2 py-1 bg-red-500 text-white hover:bg-red-600"
@click="deleteImage('image4Url')">
{{ t('common.delete') }}
</button>
</div>
</div>
<!-- Description-->
<div class="text-2xl pa-2">{{ t('creator.sections.about.description') }}</div>
</div>
<!--Edit-->
<div v-if="isEditMode">
<v-text-field
v-model="editablePhoneNumber"
class="w-full p-2"
:label="t('creator.fields.phoneNumber')"
variant="outlined"
></v-text-field>
<v-text-field
v-model="editableEmail"
class="w-full p-2"
:label="t('creator.fields.email')"
variant="outlined"
></v-text-field>
</div>
<!-- Contact Info-->
<div v-if="!isEditMode && phoneNumber || email">
<div class="my-10 flex flex-row">
<div v-if="phoneNumber" class="flex items-center space-x-2 w-1/2 justify-center">
<i class="mdi mdi-phone-outline text-2xl"></i>
<span>{{ phoneNumber }}</span>
</div>
<!-- Affichage de l'email -->
<div v-if="email" class="flex items-center space-x-2 w-1/2 justify-center">
<i class="mdi mdi-email-outline text-2xl"></i>
<a :href="`mailto:${email}`" class="no-underline text-current">
{{ email }}
</a>
</div>
</div>
</div>
<!-- Donation Section -->
<div class="section sm:hidden">
<DonationButton
v-if="brandingStore.value?.acceptDonation"
:creator-id="brandingStore.value?.id"
:creator-name="brandingStore.value?.name"
:on-cancelled-url="baseURL + '/paymentfailed/' + brandingStore.value?.id"
:on-success-url="baseURL + '/paymentcompleted/' + brandingStore.value?.id"
/>
</div>
<!-- About Creator Section -->
<div class="section">
<AboutCreator />
</div>
</div>
</div>
</template>
<script setup>
import {onMounted, ref} from "vue";
import {useClient} from "@/plugins/api.js";
import AboutCreator from './AboutCreator.vue';
import { ref } from 'vue';
import DonationButton from "@/views/creators/DonationButton.vue";
import {useBrandingStore} from "@/stores/brandingStore.js";
import {useCreatorProfileStore} from "@/stores/creatorProfileStore.js";
import {useAuthStore} from "@/stores/authStore.js";
import {useI18n} from 'vue-i18n';
const { t } = useI18n();
const authStore = useAuthStore();
const creatorProfileStore = useCreatorProfileStore();
const brandingStore = useBrandingStore();
const client = useClient();
const baseURL = window.location.origin;
const isLoading = ref(true);
const isLoggedIn = true;
const isEditMode = ref(false);
const fallbackImage = "/medias/emptyimage.png";
// Variables réactives pour les données
const mainTitle = ref("");
const mainImageUrl = ref("");
const mainImageText = ref("");
const mainVideoText = ref("");
const imagesSubtitle = ref("");
const image1Url = ref("");
const image2Url = ref("");
const image3Url = ref("");
const image4Url = ref("");
const imagesText = ref("");
const videoSubtitle = ref("");
const videoSubtitleMain = ref("");
const videoUrlMain = ref("");
const phoneNumber = ref("");
const email = ref("");
// Editable fields
const editableMainTitle = ref("");
const editableMainImageText = ref("");
const editableMainVideoText = ref("");
const editableImagesText = ref("");
const editableVideoSubtitle = ref("");
const editableVideoUrlMain = ref("");
const editablePhoneNumber = ref("");
const editableEmail = ref("");
const editableImages = ref([null, null, null, null]);
// Activer/désactiver le mode édition
function toggleEditMode() {
isEditMode.value = !isEditMode.value;
if (isEditMode.value) {
// Charger les valeurs pour l'édition
editableMainTitle.value = mainTitle.value;
editableMainImageText.value = mainImageText.value;
editableMainVideoText.value = mainVideoText.value;
editableImagesText.value = imagesText.value;
editableVideoSubtitle.value = videoSubtitle.value;
editableVideoUrlMain.value = videoUrlMain.value;
editablePhoneNumber.value = phoneNumber.value;
editableEmail.value = email.value;
} else {
// Sauvegarder les modifications
mainTitle.value = editableMainTitle.value;
mainImageText.value = editableMainImageText.value;
mainVideoText.value = editableMainVideoText.value;
imagesText.value = editableImagesText.value;
videoSubtitle.value = editableVideoSubtitle.value;
videoUrlMain.value = editableVideoUrlMain.value;
phoneNumber.value = editablePhoneNumber.value;
email.value = editableEmail.value;
// Réinitialisation des images supprimées à des strings vides si nécessaire
if (mainImageUrl.value === null) mainImageUrl.value = "";
if (image1Url.value === null) image1Url.value = "";
if (image2Url.value === null) image2Url.value = "";
if (image3Url.value === null) image3Url.value = "";
if (image4Url.value === null) image4Url.value = "";
}
}
// Supprimer une image
function deleteImage(field) {
switch (field) {
case "mainImageUrl":
mainImageUrl.value = ""; // Remplace par un string vide
break;
case "image1Url":
image1Url.value = ""; // Remplace par un string vide
break;
case "image2Url":
image2Url.value = ""; // Remplace par un string vide
break;
case "image3Url":
image3Url.value = ""; // Remplace par un string vide
break;
case "image4Url":
image4Url.value = ""; // Remplace par un string vide
break;
}
}
// Mettre à jour une image
function updateImage(field, event) {
const file = event.target.files[0];
if (file) {
switch (field) {
case "mainImageUrl":
editableImages.value[0] = file;
mainImageUrl.value = URL.createObjectURL(file);
break;
case "image1Url":
editableImages.value[1] = file;
image1Url.value = URL.createObjectURL(file);
break;
case "image2Url":
editableImages.value[2] = file;
image2Url.value = URL.createObjectURL(file);
break;
case "image3Url":
editableImages.value[3] = file;
image3Url.value = URL.createObjectURL(file);
break;
case "image4Url":
editableImages.value[4] = file;
image4Url.value = URL.createObjectURL(file);
break;
}
}
}
// Charger les données au montage
onMounted(() => {
if (brandingStore.presentationInfos === undefined) return;
mainTitle.value = brandingStore.presentationInfos.title;
mainImageUrl.value = brandingStore.presentationInfos.mainImageUrl;
mainImageText.value = brandingStore.presentationInfos.mainImageText;
mainVideoText.value = brandingStore.presentationInfos.mainVideoText;
imagesSubtitle.value = brandingStore.presentationInfos.imagesSubtitle;
image1Url.value = brandingStore.presentationInfos.image1Url;
image2Url.value = brandingStore.presentationInfos.image2Url;
image3Url.value = brandingStore.presentationInfos.image3Url;
image4Url.value = brandingStore.presentationInfos.image4Url;
imagesText.value = brandingStore.presentationInfos.imagesText;
videoSubtitle.value = brandingStore.presentationInfos.videoSubtitle;
videoSubtitleMain.value = brandingStore.presentationInfos.videoSubtitleMain;
videoUrlMain.value = brandingStore.presentationInfos.videoUrlMain;
phoneNumber.value = brandingStore.presentationInfos.phoneNumber;
email.value = brandingStore.presentationInfos.email;
});
async function saveChanges() {
if (!creatorProfileStore.creator.id) {
console.error("L'ID du créateur est manquant !");
return;
}
const formData = new FormData();
// Ajout des champs textuels
formData.append("PhoneNumber", editablePhoneNumber.value || "");
formData.append("Email", editableEmail.value || "");
formData.append("Title", editableMainTitle.value || "");
formData.append("MainImageText", editableMainImageText.value || "");
formData.append("MainVideoText", editableMainVideoText.value || "");
formData.append("ImagesText", editableImagesText.value || "");
formData.append("VideoSubtitle", editableVideoSubtitle.value || "");
formData.append("VideoUrlMain", editableVideoUrlMain.value || "");
// Ajout des URLs d'images supprimées
formData.append("MainImageUrl", mainImageUrl.value || ""); // Peut contenir un string vide
formData.append("Image1Url", image1Url.value || "");
formData.append("Image2Url", image2Url.value || "");
formData.append("Image3Url", image3Url.value || "");
formData.append("Image4Url", image4Url.value || "");
// Ajout des fichiers d'images téléversées
if (editableImages.value[0]) formData.append("MainImage", editableImages.value[0]);
if (editableImages.value[1]) formData.append("Image1", editableImages.value[1]);
if (editableImages.value[2]) formData.append("Image2", editableImages.value[2]);
if (editableImages.value[3]) formData.append("Image3", editableImages.value[3]);
if (editableImages.value[4]) formData.append("Image4", editableImages.value[4]);
try {
isLoading.value = true;
const response = await client.post(
`/api/creators/${creatorProfileStore.creator.id}/presentation-infos`,
formData,
{headers: {"Content-Type": "multipart/form-data"}}
);
// Mettre à jour les valeurs locales pour refléter les changements
mainTitle.value = editableMainTitle.value;
mainImageText.value = editableMainImageText.value;
mainVideoText.value = editableMainVideoText.value;
imagesText.value = editableImagesText.value;
videoSubtitle.value = editableVideoSubtitle.value;
videoUrlMain.value = editableVideoUrlMain.value;
phoneNumber.value = editablePhoneNumber.value;
email.value = editableEmail.value;
console.log("Données sauvegardées :", response.data);
isEditMode.value = false;
} catch (error) {
console.error("Erreur lors de la sauvegarde :", error);
} finally {
isLoading.value = false;
}
}
function cancelEdit() {
// Restaurer les valeurs d'origine
editableMainTitle.value = mainTitle.value;
editableMainImageText.value = mainImageText.value;
editableMainVideoText.value = mainVideoText.value;
editableImagesText.value = imagesText.value;
editableVideoSubtitle.value = videoSubtitle.value;
editableVideoUrlMain.value = videoUrlMain.value;
editablePhoneNumber.value = phoneNumber.value;
editableEmail.value = email.value;
// Désactiver le mode édition
isEditMode.value = false;
}
</script>
<style scoped>
.video-container {
position: relative;
width: 100%;
padding-top: 56.25%; /* Ratio 16:9 (9/16 = 0.5625) */
.creator-home {
@apply w-full;
@apply p-5;
}
.video-frame {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
border-radius: 0.5rem; /* Pour les bords arrondis */
.content-sections {
@apply flex flex-col;
@apply gap-5;
}
.section {
@apply rounded-2xl;
@apply shadow-2xl;
@apply relative;
}
.section::before {
content: '';
@apply absolute inset-0;
@apply rounded-2xl;
@apply p-[1px];
background: linear-gradient(135deg, rgba(64, 64, 64, 1) 0%, rgba(64, 64, 64, 0) 20%, rgba(64, 64, 64, 0.5) 100%);
mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
mask-composite: exclude;
pointer-events: none;
}
</style>
<i18n>
{
"en": {
"common": {
"save": "Save",
"edit": "Edit",
"cancel": "Cancel",
"delete": "Delete"
},
"creator": {
"sections": {
"about": {
"title": "About",
"description": "Description",
"mainImage": "Main image",
"image1": "Image 1",
"image2": "Image 2",
"image3": "Image 3",
"image4": "Image 4",
"images": "Images"
},
"support": {
"title": "Support",
"description": "Description",
"subtitle": "Subtitle"
}
},
"fields": {
"videoUrl": "Video URL",
"phoneNumber": "Phone Number",
"email": "Email"
"home": {
"title": "Creator Home"
}
}
},
"fr": {
"common": {
"save": "Enregistrer",
"edit": "Modifier",
"cancel": "Annuler",
"delete": "Supprimer"
},
"creator": {
"sections": {
"about": {
"title": "À propos",
"description": "Description",
"mainImage": "Image principale",
"image1": "Image 1",
"image2": "Image 2",
"image3": "Image 3",
"image4": "Image 4",
"images": "Images"
},
"support": {
"title": "Support",
"description": "Description",
"subtitle": "Sous-titre"
}
},
"fields": {
"videoUrl": "URL de la vidéo",
"phoneNumber": "Numéro de téléphone",
"email": "Email"
"home": {
"title": "Accueil du Créateur"
}
}
},
"es": {
"common": {
"save": "Guardar",
"edit": "Editar",
"cancel": "Cancelar",
"delete": "Eliminar"
},
"creator": {
"sections": {
"about": {
"title": "Acerca de",
"description": "Descripción",
"mainImage": "Imagen principal",
"image1": "Imagen 1",
"image2": "Imagen 2",
"image3": "Imagen 3",
"image4": "Imagen 4",
"images": "Imágenes"
},
"support": {
"title": "Soporte",
"description": "Descripción",
"subtitle": "Subtítulo"
}
},
"fields": {
"videoUrl": "URL del video",
"phoneNumber": "Número de teléfono",
"email": "Correo electrónico"
"home": {
"title": "Inicio del Creador"
}
}
}