Browse Source

feat: codigo unico para favorito

Gustavo Zanatta 1 week ago
parent
commit
c679d460b8
4 changed files with 107 additions and 10 deletions
  1. 7 1
      src/i18n/locales/en.json
  2. 7 1
      src/i18n/locales/es.json
  3. 7 1
      src/i18n/locales/pt.json
  4. 86 7
      src/pages/profile/ProfilePage.vue

+ 7 - 1
src/i18n/locales/en.json

@@ -519,7 +519,13 @@
   "profile": {
     "title": "Profile",
     "share": {
-      "message": "Download the Diária App and hire a service with {name}."
+      "message": "Download the Diária App and book a service with {name}. Use the code {code} in the app's Favorites tab to add me to your favorites automatically 👇\n{link}",
+      "title": "Diária App",
+      "dialog_title": "Share profile",
+      "code_label": "My code:",
+      "code_copied": "Code copied!",
+      "copied": "Message copied! Paste it on WhatsApp to share.",
+      "error": "Could not share the profile. Please try again."
     },
     "edit_profile": "Edit profile",
     "edit_data": "My data",

+ 7 - 1
src/i18n/locales/es.json

@@ -519,7 +519,13 @@
   "profile": {
     "title": "Perfil",
     "share": {
-      "message": "Descarga la app Diária y contrata un servicio con {name}."
+      "message": "Descarga la app Diária y contrata un servicio con {name}. Usa el código {code} en la pestaña Favoritos de la app para añadirme automáticamente a tus favoritos 👇\n{link}",
+      "title": "Diária App",
+      "dialog_title": "Compartir perfil",
+      "code_label": "Mi código:",
+      "code_copied": "¡Código copiado!",
+      "copied": "¡Mensaje copiado! Pégalo en WhatsApp para compartir.",
+      "error": "No se pudo compartir el perfil. Inténtalo de nuevo."
     },
     "edit_profile": "Editar perfil",
     "edit_data": "Mis datos",

+ 7 - 1
src/i18n/locales/pt.json

@@ -522,7 +522,13 @@
   "profile": {
     "title": "Perfil",
     "share": {
-      "message": "Baixe o Diária App e contrate um serviço com {name}."
+      "message": "Baixe o Diária App e contrate um serviço com {name}. Use o código {code} na aba Favoritos do app para me adicionar automaticamente aos seus favoritos 👇\n{link}",
+      "title": "Diária App",
+      "dialog_title": "Compartilhar perfil",
+      "code_label": "Meu código:",
+      "code_copied": "Código copiado!",
+      "copied": "Mensagem copiada! Cole no WhatsApp para compartilhar.",
+      "error": "Não foi possível compartilhar o perfil. Tente novamente."
     },
     "edit_profile": "Editar perfil",
     "edit_data": "Meu dados",

+ 86 - 7
src/pages/profile/ProfilePage.vue

@@ -20,7 +20,27 @@
           <div class="fonte-nome-profile font16 fontbold q-mt-md text-text">{{ user.name || '—' }}</div>
           <div class="fonte-email-profile font9 fontmedium text-grey-6 q-my-sm">{{ user.email || '—' }}</div>
           <div class="fonte-telefone-profile font9 fontmedium text-grey-7">{{ user.phone || '—' }}</div> 
-          
+
+          <div
+            v-if="shareCode"
+            class="row no-wrap q-gutter-x-xs q-mt-sm share-code cursor-pointer"
+            @click="copyShareCode"
+          >
+            <div class="font9 fontmedium text-grey-6 q-my-auto">
+              <span>
+                {{ $t('profile.share.code_label') }}
+              </span>
+            </div>
+
+            <div class="font12 fontbold gradient-diarista q-my-auto">
+              <span>
+                {{ shareCode }}
+              </span>
+            
+            </div>
+            <q-icon class="q-my-auto" name="mdi-content-copy" size="14px" color="grey-6" />
+          </div>
+
           <q-btn
             v-if="!isPendingProvider"
             outline
@@ -150,7 +170,7 @@
 </template>
 
 <script setup>
-import { ref, onMounted } from 'vue';
+import { computed, ref, onMounted } from 'vue';
 import { useQuasar } from 'quasar';
 import { useI18n } from 'vue-i18n';
 import { Browser } from '@capacitor/browser';
@@ -169,6 +189,7 @@ import { useRouter } from 'vue-router';
 
 const PRIVACY_POLICY_URL = 'https://politicas.softpar.inf.br/politicas/politicaDiaristaPrestador.html';
 const SUPPORT_PAGE_URL   = 'https://politicas.softpar.inf.br/suportes/suporteDiaristaPrestador.html';
+const CLIENT_APP_STORE_URL = 'https://play.google.com/store/apps/details?id=br.com.diarista.client';
 
 const appVersion = process.env.APP_VERSION;
 
@@ -184,25 +205,79 @@ const user = ref({
   phone: ''
 });
 
-// compartilha perfil 
+const shareCode = computed(() => user.value.provider_share_code || '');
+
+const shareMessage = computed(() => t('profile.share.message', {
+  name: user.value.name,
+  code: shareCode.value,
+  link: CLIENT_APP_STORE_URL,
+}));
+
+const isShareCanceled = (error) => {
+  const message = String(error?.message ?? '').toLowerCase();
+
+  return error?.name === 'AbortError' || message.includes('canceled') || message.includes('cancelled');
+};
+
+const copyToClipboard = async (text) => {
+  try {
+    if (navigator?.clipboard?.writeText) {
+      await navigator.clipboard.writeText(text);
+
+      return true;
+    }
+  } catch (error) {
+    console.error('Erro ao copiar mensagem:', error);
+  }
+
+  return false;
+};
+
+// compartilha perfil
 const shareProfile = async () => {
-  const message = t('profile.share.message', { name: user.value.name });
+  const message = shareMessage.value;
 
   try {
+    const { value: canShare } = await Share.canShare();
+
+    if (!canShare) {
+      throw new Error('Share unavailable');
+    }
+
     await Share.share({
-      title: 'Diária App',
+      title: t('profile.share.title'),
       text: message,
-      dialogTitle: 'Compartilhar perfil',
+      dialogTitle: t('profile.share.dialog_title'),
     });
   } catch (error) {
-    if (error?.name === 'AbortError') {
+    if (isShareCanceled(error)) {
       return;
     }
 
     console.error('Erro ao compartilhar perfil:', error);
+
+    const copied = await copyToClipboard(message);
+
+    $q.notify({
+      message: copied ? t('profile.share.copied') : t('profile.share.error'),
+      color: copied ? 'positive' : 'negative',
+    });
   }
 };
 
+const copyShareCode = async () => {
+  if (!shareCode.value) {
+    return;
+  }
+
+  const copied = await copyToClipboard(shareCode.value);
+
+  $q.notify({
+    message: copied ? t('profile.share.code_copied') : t('profile.share.error'),
+    color: copied ? 'positive' : 'negative',
+  });
+};
+
 const openEditProfile = () => {
   $q.dialog({
     component: ProfileEditDialog,
@@ -278,6 +353,10 @@ onMounted(async () => {
   position: relative;
 }
 
+.share-code {
+  letter-spacing: 0.5px;
+}
+
 .btn-edit-profile {
   border-radius: 6px;
 }