Răsfoiți Sursa

refactor: format fantasy name

Gustavo Mantovani 1 săptămână în urmă
părinte
comite
f38c1cd13c

+ 2 - 1
src/components/layout/DefaultHeaderPage.vue

@@ -266,6 +266,7 @@ import { useRoute, useRouter } from "vue-router";
 import { useI18n } from "vue-i18n";
 import { userStore } from "src/stores/user";
 import { useAuth } from "src/composables/useAuth";
+import { formatUnitName } from "src/helpers/utils";
 import {
   getMyNotifications,
   getUnreadCount,
@@ -304,7 +305,7 @@ const user = computed(() => store.user);
 const unitLabel = computed(() => {
   const units = store.user?.units ?? [];
   if (!units.length) return "Franqueadora / Matriz";
-  return units.map((u) => u.fantasy_name).join(", ");
+  return units.map((unit) => formatUnitName(unit)).join(", ");
 });
 
 // ------------------- Notificações (sino) -------------------

+ 2 - 1
src/components/selects/UnitMultiSelect.vue

@@ -28,6 +28,7 @@
 <script setup>
 import { onMounted, ref, watch } from "vue";
 import { getUnitsForSelect } from "src/api/unit";
+import { formatUnitName } from "src/helpers/utils";
 
 const { label, initialIds, bgColor } = defineProps({
   label: { type: String, default: "Unidades" },
@@ -62,7 +63,7 @@ onMounted(async () => {
   try {
     const response = await getUnitsForSelect();
     unitOptions.value = response.map((unit) => ({
-      label: unit.fantasy_name,
+      label: formatUnitName(unit),
       value: unit.id,
     }));
     filteredOptions.value = unitOptions.value;

+ 2 - 1
src/components/selects/UnitSelect.vue

@@ -26,6 +26,7 @@
 import { onMounted, ref, watch } from "vue";
 import { getUnitsForSelect } from "src/api/unit";
 import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
+import { formatUnitName } from "src/helpers/utils";
 
 const { placeholder, label, initialId } = defineProps({
   placeholder: { type: String, default: "Buscar unidade" },
@@ -59,7 +60,7 @@ onMounted(async () => {
   try {
     const response = await getUnitsForSelect();
     unitOptions.value = response.map((unit) => ({
-      label: unit.fantasy_name,
+      label: formatUnitName(unit),
       value: unit.id,
     }));
     filteredOptions.value = unitOptions.value;

+ 13 - 0
src/helpers/utils.js

@@ -107,6 +107,18 @@ const formatPercentage = (value) => {
   return `${(value * 100).toFixed(0)}%`;
 };
 
+const normalizeUnitName = (value) => {
+  const name = String(value ?? "").trim();
+  return name && !["null", "undefined"].includes(name.toLowerCase())
+    ? name
+    : null;
+};
+
+const formatUnitName = (unit, fallback = "—") =>
+  normalizeUnitName(unit?.fantasy_name) ||
+  normalizeUnitName(unit?.social_reason) ||
+  fallback;
+
 export {
   formatDateDMYtoYMD,
   formatDateYMDtoDMY,
@@ -115,4 +127,5 @@ export {
   formatToBRLCurrency,
   normalizeString,
   formatPercentage,
+  formatUnitName,
 };

+ 2 - 1
src/pages/cadastros/components/AddEditGroupDialog.vue

@@ -61,6 +61,7 @@ import { useDialogPluginComponent } from "quasar";
 import { useInputRules } from "src/composables/useInputRules";
 import { getUnitsForSelect } from "src/api/unit";
 import { createGroup, updateGroup } from "src/api/group";
+import { formatUnitName } from "src/helpers/utils";
 import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
 import DefaultInput from "src/components/defaults/DefaultInput.vue";
 
@@ -94,7 +95,7 @@ onMounted(async () => {
   try {
     const units = await getUnitsForSelect();
     unitOptions.value = units.map((u) => ({
-      label: u.fantasy_name,
+      label: formatUnitName(u),
       value: u.id,
     }));
   } catch (error) {

+ 2 - 1
src/pages/dashboard/StudentDetailPage.vue

@@ -20,7 +20,7 @@
             <div class="text-subtitle2 text-grey-6 q-mb-xs">Contato / Unidade</div>
             <div class="text-body1 text-dark">{{ student.phone ?? "—" }}</div>
             <div class="text-caption text-grey-6">
-              {{ student.unit?.fantasy_name ?? "—" }}
+              {{ formatUnitName(student.unit) }}
             </div>
           </q-card-section>
 
@@ -55,6 +55,7 @@ import { ref, onMounted } from "vue";
 import { useRoute } from "vue-router";
 import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
 import { getFranchisorStudentDetail } from "src/api/student";
+import { formatUnitName } from "src/helpers/utils";
 
 const route = useRoute();
 const loading = ref(true);

+ 2 - 1
src/pages/dashboard/components/ActiveStudentsDialog.vue

@@ -86,6 +86,7 @@ import { ref, computed, onMounted } from "vue";
 import { useDialogPluginComponent } from "quasar";
 import { useRouter } from "vue-router";
 import { getFranchisorActiveStudents } from "src/api/student";
+import { formatUnitName } from "src/helpers/utils";
 
 const props = defineProps({
   unitIds: { type: Array, default: () => [] },
@@ -109,7 +110,7 @@ onMounted(async () => {
       id: s.id,
       name: s.name,
       phone: s.phone ?? "—",
-      unit: s.unit?.fantasy_name ?? "—",
+      unit: formatUnitName(s.unit),
     }));
   } catch {
     // silent

+ 2 - 2
src/pages/franchisee/FranchiseePage.vue

@@ -23,14 +23,14 @@
 import { getUnits, deleteUnit } from "src/api/unit";
 import DefaultTable from "src/components/defaults/DefaultTable.vue";
 import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
-import { formatDateYMDtoDMY } from "src/helpers/utils";
+import { formatDateYMDtoDMY, formatUnitName } from "src/helpers/utils";
 import { ref } from "vue";
 
 const columns = ref([
   {
     name: "fantasy_name",
     label: "Unidade",
-    field: "fantasy_name",
+    field: (row) => formatUnitName(row),
     align: "left",
     sortable: true,
   },

+ 6 - 2
src/pages/packages/components/AddEditPackageDialog.vue

@@ -280,7 +280,7 @@
                       <q-separator />
                       <div class="row items-center q-px-sm q-py-sm">
                         <span class="col text-body2 row items-center q-gutter-x-xs">
-                          {{ unit.fantasy_name }}
+                          {{ formatUnitName(unit) }}
                           <q-icon
                             v-if="lockedUnitIds.has(unit.id)"
                             name="mdi-lock"
@@ -471,6 +471,7 @@ import { getUnitsForSelect } from "src/api/unit";
 import { getPackage, createPackage, updatePackage } from "src/api/package";
 import { getProductsForSelect } from "src/api/product";
 import { getGroupsForSelect } from "src/api/group";
+import { formatUnitName } from "src/helpers/utils";
 
 defineEmits([...useDialogPluginComponent.emits]);
 
@@ -625,7 +626,9 @@ watch(
 const filteredUnits = computed(() => {
   const q = unitSearch.value.toLowerCase();
   if (!q) return units.value;
-  return units.value.filter((u) => u.fantasy_name.toLowerCase().includes(q));
+  return units.value.filter((unit) =>
+    formatUnitName(unit).toLowerCase().includes(q),
+  );
 });
 
 const setAllVisible = (visible) => {
@@ -696,6 +699,7 @@ onMounted(async () => {
     units.value = allUnits.map((u) => ({
       id: u.id,
       fantasy_name: u.fantasy_name,
+      social_reason: u.social_reason,
       visible: groupLockedIds.has(u.id) ? true : (visibilityMap[u.id] ?? true),
     }));
 

+ 2 - 2
src/pages/tbr/tabs/BillingsTab.vue

@@ -67,7 +67,7 @@ import DefaultTable from "src/components/defaults/DefaultTable.vue";
 import GenerateReceivableDialog from "src/pages/tbr/components/GenerateReceivableDialog.vue";
 
 import api from "src/api";
-import { formatToBRLCurrency } from "src/helpers/utils";
+import { formatToBRLCurrency, formatUnitName } from "src/helpers/utils";
 import { permissionStore } from "src/stores/permission";
 
 const $q = useQuasar();
@@ -79,7 +79,7 @@ const columns = [
   {
     name: "unit_id",
     label: "Unidade",
-    field: (row) => row.unit?.fantasy_name ?? `#${row.unit_id}`,
+    field: (row) => formatUnitName(row.unit, `#${row.unit_id}`),
     align: "left",
   },
   {

+ 0 - 1
src/pages/unit/tabs/UnitDataTab.vue

@@ -18,7 +18,6 @@
             label="Nome Fantasia"
             class="col-12"
             outlined
-            :rules="[inputRules.required]"
           />
 
           <DefaultInput