From 53e6c67ff9b310b972e19ebfb6939233467704a6 Mon Sep 17 00:00:00 2001
From: Javier Segarra <jsegarra@verdnatura.es>
Date: Sun, 8 Sep 2024 12:56:40 +0200
Subject: [PATCH] perf: minor clean code

---
 src/pages/Item/ItemFixedPrice.vue | 41 ++++++++++++++-----------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/src/pages/Item/ItemFixedPrice.vue b/src/pages/Item/ItemFixedPrice.vue
index 951dbf4b2..59a3e74db 100644
--- a/src/pages/Item/ItemFixedPrice.vue
+++ b/src/pages/Item/ItemFixedPrice.vue
@@ -263,8 +263,6 @@ const updateMinPrice = async (value, props) => {
 };
 
 const upsertPrice = async ({ row }, resetMinPrice = false) => {
-    // if (!validations(row, rowIndex, col)) return;
-
     try {
         if (resetMinPrice) row.hasMinPrice = 0;
         row = await upsertFixedPrice(row);
@@ -272,6 +270,7 @@ const upsertPrice = async ({ row }, resetMinPrice = false) => {
         console.error('Error editing price', err);
     }
 };
+
 async function upsertFixedPrice(row) {
     try {
         const { data } = await axios.patch('FixedPrices/upsertFixedPrice', row);
@@ -280,6 +279,7 @@ async function upsertFixedPrice(row) {
         console.error('Error editing price', err);
     }
 }
+
 async function saveOnRowChange(row) {
     if (rowsSelected.value.length > 1) return;
     if (rowsSelected.value[0]?.id === row.id) return;
@@ -298,11 +298,9 @@ function checkLastVisibleRow() {
         }
     });
 
-    if (lastVisibleRow) {
-        console.log('Ăšltima fila visible:', lastVisibleRow);
-    }
     return lastVisibleRow;
 }
+
 const addRow = (original = null) => {
     let copy = null;
     if (!original) {
@@ -340,8 +338,10 @@ const addRow = (original = null) => {
         };
     return { original, copy };
 };
+
 const getTableRows = () =>
     document.getElementsByClassName('q-table')[0].querySelectorAll('tr.cursor-pointer');
+
 function highlightNewRow({ $index: index }) {
     const row = getTableRows()[index];
     if (row) {
@@ -354,10 +354,12 @@ function highlightNewRow({ $index: index }) {
 const openEditTableCellDialog = () => {
     editTableCellDialogRef.value.show();
 };
+
 const onEditCellDataSaved = async () => {
     rowsSelected.value = [];
     tableRef.value.reload();
 };
+
 const removeFuturePrice = async () => {
     try {
         rowsSelected.value.forEach(({ id }) => {
@@ -368,6 +370,7 @@ const removeFuturePrice = async () => {
         console.error('Error removing price', err);
     }
 };
+
 function confirmRemove(item, isFuture) {
     const promise = async () =>
         isFuture ? removeFuturePrice(item.id) : removePrice(item.id);
@@ -380,6 +383,7 @@ function confirmRemove(item, isFuture) {
         },
     });
 }
+
 const removePrice = async (id) => {
     try {
         await axios.delete(`FixedPrices/${id}`);
@@ -389,6 +393,13 @@ const removePrice = async (id) => {
         console.error('Error removing price', err);
     }
 };
+const dateStyle = (date) =>
+    date
+        ? {
+              'bg-color': 'warning',
+              'is-outlined': true,
+          }
+        : {};
 
 function handleOnDataSave({ CrudModelRef }) {
     const { original, copy } = addRow(CrudModelRef.formData[checkLastVisibleRow()]);
@@ -566,14 +577,7 @@ function handleOnDataSave({ CrudModelRef }) {
                         :show-event="true"
                         v-model="props.row.started"
                         v-on="getRowUpdateInputEvents(props, false, 'date')"
-                        v-bind="
-                            isBigger(props.row.started)
-                                ? {
-                                      'bg-color': 'warning',
-                                      'is-outlined': true,
-                                  }
-                                : {}
-                        "
+                        v-bind="dateStyle(isBigger(props.row.started))"
                     />
                 </QTd>
             </template>
@@ -584,14 +588,7 @@ function handleOnDataSave({ CrudModelRef }) {
                         :show-event="true"
                         v-model="props.row.ended"
                         v-on="getRowUpdateInputEvents(props, false, 'date')"
-                        v-bind="
-                            isLower(props.row.started)
-                                ? {
-                                      'bg-color': 'warning',
-                                      'is-outlined': true,
-                                  }
-                                : {}
-                        "
+                        v-bind="dateStyle(isLower(props.row.started))"
                     />
                 </QTd>
             </template>
@@ -617,7 +614,7 @@ function handleOnDataSave({ CrudModelRef }) {
                         color="primary"
                         @click.stop="
                             openConfirmationModal(
-                                t('This row will be removed'),
+                                t('globals.rowWillBeRemoved'),
                                 t('Do you want to clone this item?'),
                                 () => removePrice(row.id, rowIndex)
                             )