Просмотр исходного кода

feat: add nome da unidade (name)

Gustavo Mantovani 1 день назад
Родитель
Сommit
0854cd0ea8

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

@@ -226,6 +226,12 @@
               >
                 <div class="settings-panel q-pa-md">
                   <div class="column q-gutter-y-sm">
+                    <div>
+                      <span class="text-caption text-grey-6">Nome da Unidade</span>
+                      <div class="text-body2 text-primary text-weight-medium ellipsis">
+                        {{ unitInfo.name || "Não informado" }}
+                      </div>
+                    </div>
                     <div>
                       <span class="text-caption text-grey-6">Nome fantasia</span>
                       <div class="text-body2 text-primary text-weight-medium ellipsis">
@@ -289,6 +295,7 @@ import { userStore } from "src/stores/user";
 import { useAuth } from "src/composables/useAuth";
 import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
 import { getUnitMe } from "src/api/unit";
+import { formatUnitName } from "src/helpers/utils";
 import {
   getMyNotifications,
   getUnreadCount,
@@ -328,8 +335,7 @@ const userUnits = computed(() => store.user?.units ?? []);
 const user = computed(() => store.user);
 const unitDetails = ref(null);
 const unitInfo = computed(() => unitDetails.value || store.selectedUnit || {});
-const getUnitLabel = (unit) =>
-  unit?.fantasy_name || unit?.social_reason || "Unidade sem nome";
+const getUnitLabel = (unit) => formatUnitName(unit);
 
 // ------------------- Notificações (sino) -------------------
 const notifications = ref([]);

+ 14 - 0
src/helpers/utils.js

@@ -111,6 +111,19 @@ const normalizeString = (val) =>
     .normalize("NFKD")
     .replace(/[\u0300-\u036f~]/g, "");
 
+const normalizeUnitName = (value) => {
+  const name = String(value ?? "").trim();
+  return name && !["null", "undefined"].includes(name.toLowerCase())
+    ? name
+    : null;
+};
+
+const formatUnitName = (unit, fallback = "Unidade sem nome") =>
+  normalizeUnitName(unit?.name) ||
+  normalizeUnitName(unit?.fantasy_name) ||
+  normalizeUnitName(unit?.social_reason) ||
+  fallback;
+
 export {
   formatDateDMYtoYMD,
   formatDateYMDtoDMY,
@@ -118,4 +131,5 @@ export {
   convertDateTime,
   formatToBRLCurrency,
   normalizeString,
+  formatUnitName,
 };

+ 2 - 1
src/pages/unit/UnitActionPage.vue

@@ -58,13 +58,14 @@ const canViewFinancial = computed(() =>
 
 const { form, getFormAsFormData, setUpdateFormAsOriginal } =
   useFormUpdateTracker({
+    name: null,
     address_number: null,
     cell_number: null,
     city_id: null,
     cnpj: null,
     complement: null,
     email: null,
-    fantasy_name: null,
+    fantasy_name: "",
     name_responsible: null,
     neighborhood: null,
     phone_number: null,

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

@@ -5,6 +5,14 @@
         <AvatarImageComponent ref="avatarRef" @update:file="onAvatarChange" />
 
         <div class="row full-width q-mt-md q-col-gutter-sm">
+          <DefaultInput
+            :model-value="form.name"
+            class="col-12"
+            disable
+            label="Nome da Unidade"
+            outlined
+          />
+
           <DefaultInput
             :model-value="form.social_reason"
             class="col-12"
@@ -237,7 +245,13 @@ async function onSave() {
 onMounted(async () => {
   try {
     const unit = await getUnitMe();
-    form.value.fantasy_name = unit.fantasy_name;
+    form.value.name = unit.name ?? null;
+    const fantasyName = String(unit.fantasy_name ?? "").trim();
+    form.value.fantasy_name = ["null", "undefined"].includes(
+      fantasyName.toLowerCase(),
+    )
+      ? ""
+      : fantasyName;
     form.value.social_reason = unit.social_reason;
     form.value.cnpj = unit.cnpj;
     form.value.state_registration = unit.state_registration;