Cambio de localstorage a session y click solo cuando hay fechas disponibles
This commit is contained in:
parent
ac8dbff26d
commit
fded48a627
|
@ -53,15 +53,15 @@ export default defineComponent({
|
||||||
return formattedDate;
|
return formattedDate;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
postalCodeValid.value.isValid = true;
|
|
||||||
if(!dates.length) {
|
if(!dates.length) {
|
||||||
quasarNotify({
|
quasarNotify({
|
||||||
type: "erro",
|
type: "erro",
|
||||||
message: `No tenemos fechas de entrega posibles para este código postal`,
|
message: `No tenemos fechas de entrega posibles para este código postal`,
|
||||||
});
|
});
|
||||||
setFieldError("postalCode", M.fiveLength);
|
setFieldError("postalCode", M.fiveLength);
|
||||||
postalCodeValid.value.isValid = false;
|
postalCodeValid.value.isValid = false;
|
||||||
|
} else {
|
||||||
|
postalCodeValid.value.isValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
postalCodeValid.value.dataOptions = dates;
|
postalCodeValid.value.dataOptions = dates;
|
||||||
|
|
|
@ -44,8 +44,8 @@ export default defineComponent({
|
||||||
const { navPos, screenWidth, slide, target } = useVerticalCarouselImgs();
|
const { navPos, screenWidth, slide, target } = useVerticalCarouselImgs();
|
||||||
|
|
||||||
const formStore = useFormStore();
|
const formStore = useFormStore();
|
||||||
const { getItem } = useLocalStorage();
|
const { getItemSession } = useLocalStorage();
|
||||||
const localValues = getItem("availability");
|
const localValues = getItemSession("availability");
|
||||||
const lengthCp = 5;
|
const lengthCp = 5;
|
||||||
|
|
||||||
const { postalCodeValid } = storeToRefs(formStore);
|
const { postalCodeValid } = storeToRefs(formStore);
|
||||||
|
@ -63,7 +63,7 @@ export default defineComponent({
|
||||||
if (e.target.value.length === lengthCp && isEventKeyActive) {
|
if (e.target.value.length === lengthCp && isEventKeyActive) {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
modalDate.click();
|
if(postalCodeValid.value.isValid) modalDate.click();
|
||||||
isEventKeyActive = false;
|
isEventKeyActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { checkoutSchema } from "src/utils/zod/schemas";
|
||||||
import { useLocalStorage } from "./useLocalStorage";
|
import { useLocalStorage } from "./useLocalStorage";
|
||||||
|
|
||||||
export function useCheckoutForm() {
|
export function useCheckoutForm() {
|
||||||
const { addItem, getItem, removeItem } = useLocalStorage();
|
const { addItem, getItem, getItemSession, removeItem } = useLocalStorage();
|
||||||
|
|
||||||
//! Elements ref
|
//! Elements ref
|
||||||
const postalCodeRef = ref(null);
|
const postalCodeRef = ref(null);
|
||||||
|
@ -26,7 +26,7 @@ export function useCheckoutForm() {
|
||||||
const { handleCheckoutData } = formStore;
|
const { handleCheckoutData } = formStore;
|
||||||
|
|
||||||
const availability =
|
const availability =
|
||||||
availabilityForm.value.dateExpired || getItem("availability");
|
availabilityForm.value.dateExpired || getItemSession("availability");
|
||||||
|
|
||||||
const phoneData = ref({
|
const phoneData = ref({
|
||||||
country: {
|
country: {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { LocalStorage } from "quasar";
|
import { LocalStorage, SessionStorage } from "quasar";
|
||||||
|
|
||||||
export function useLocalStorage() {
|
export function useLocalStorage() {
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,15 @@ export function useLocalStorage() {
|
||||||
LocalStorage.set(`@${key}`, stringifyValue);
|
LocalStorage.set(`@${key}`, stringifyValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an item to SessionStorage.
|
||||||
|
* @param {string} key - The key of the item to be added.
|
||||||
|
* @param {*} value - The value of the item to be added.
|
||||||
|
*/
|
||||||
|
const addItemSession = (key, value) => {
|
||||||
|
SessionStorage.set(`@${key}`, stringifyValue);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an item from the local storage based on the provided key.
|
* Retrieves an item from the local storage based on the provided key.
|
||||||
*
|
*
|
||||||
|
@ -25,6 +34,19 @@ export function useLocalStorage() {
|
||||||
return data || [];
|
return data || [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an item from the local storage based on the provided key.
|
||||||
|
*
|
||||||
|
* @param {string} key - The key of the item to retrieve.
|
||||||
|
* @returns {Object|Array} - The retrieved item from the local storage. If the key is "availability", it returns an object, otherwise it returns an array.
|
||||||
|
*/
|
||||||
|
const getItemSession = (key) => {
|
||||||
|
const data = JSON.parse(SessionStorage.getItem(`@${key}`));
|
||||||
|
|
||||||
|
if (key === "availability") return data || {};
|
||||||
|
return data || [];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an item from local storage.
|
* Remove an item from local storage.
|
||||||
*
|
*
|
||||||
|
@ -38,5 +60,7 @@ export function useLocalStorage() {
|
||||||
addItem,
|
addItem,
|
||||||
getItem,
|
getItem,
|
||||||
removeItem,
|
removeItem,
|
||||||
|
addItemSession,
|
||||||
|
getItemSession
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import { useLocalStorage } from "./useLocalStorage";
|
||||||
export function usePostalCalendar({ modalItem = "", type = "home" }) {
|
export function usePostalCalendar({ modalItem = "", type = "home" }) {
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { push } = useRouter();
|
const { push } = useRouter();
|
||||||
const { addItem, getItem, removeItem } = useLocalStorage();
|
const { addItem, getItemSession, removeItem } = useLocalStorage();
|
||||||
|
|
||||||
const modalStore = useModalStore();
|
const modalStore = useModalStore();
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ export function usePostalCalendar({ modalItem = "", type = "home" }) {
|
||||||
plantas: "Floranet Plantas",
|
plantas: "Floranet Plantas",
|
||||||
ramos: "Floranet Ramos",
|
ramos: "Floranet Ramos",
|
||||||
};
|
};
|
||||||
const availability = ref(getItem("availability"));
|
const availability = ref(getItemSession("availability"));
|
||||||
|
|
||||||
const availabilityFormKeys = computed(() => {
|
const availabilityFormKeys = computed(() => {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default defineComponent({
|
||||||
setup() {
|
setup() {
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { push } = useRouter();
|
const { push } = useRouter();
|
||||||
const { getItem } = useLocalStorage();
|
const { getItemSession } = useLocalStorage();
|
||||||
const { isAvailabilityEmpty } = usePostalCalendar({});
|
const { isAvailabilityEmpty } = usePostalCalendar({});
|
||||||
|
|
||||||
const mobileStore = useMobileStore();
|
const mobileStore = useMobileStore();
|
||||||
|
@ -54,7 +54,7 @@ export default defineComponent({
|
||||||
const { getProducts } = cartStore;
|
const { getProducts } = cartStore;
|
||||||
|
|
||||||
const isOpenOrder = ref(false);
|
const isOpenOrder = ref(false);
|
||||||
const availabilityStoraged = ref(getItem("availability"));
|
const availabilityStoraged = ref(getItemSession("availability"));
|
||||||
const isNotAllCategory = computed(() => {
|
const isNotAllCategory = computed(() => {
|
||||||
return route.path.split("/")[2] !== "all";
|
return route.path.split("/")[2] !== "all";
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,12 +43,12 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { getItem } = useLocalStorage();
|
const { getItemSession } = useLocalStorage();
|
||||||
|
|
||||||
const formStore = useFormStore();
|
const formStore = useFormStore();
|
||||||
const { availability: availabilityForm } = storeToRefs(formStore);
|
const { availability: availabilityForm } = storeToRefs(formStore);
|
||||||
|
|
||||||
const availability = ref(getItem("availability"));
|
const availability = ref(getItemSession("availability"));
|
||||||
const availabilityFormKeys = computed(() => {
|
const availabilityFormKeys = computed(() => {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.entries(availabilityForm.value).filter(
|
Object.entries(availabilityForm.value).filter(
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { useFormStore } from "./forms";
|
||||||
|
|
||||||
export const useCartStore = defineStore("cart", () => {
|
export const useCartStore = defineStore("cart", () => {
|
||||||
const { push } = useRouter();
|
const { push } = useRouter();
|
||||||
const { addItem, getItem } = useLocalStorage();
|
const { addItem, getItem, getItemSession } = useLocalStorage();
|
||||||
|
|
||||||
const formStore = useFormStore();
|
const formStore = useFormStore();
|
||||||
const { availability: availabilityForm } = storeToRefs(formStore);
|
const { availability: availabilityForm } = storeToRefs(formStore);
|
||||||
|
@ -36,7 +36,7 @@ export const useCartStore = defineStore("cart", () => {
|
||||||
|
|
||||||
//! Variables
|
//! Variables
|
||||||
const cart = ref(getItem("cart"));
|
const cart = ref(getItem("cart"));
|
||||||
const availability = ref(getItem("availability"));
|
const availability = ref(getItemSession("availability"));
|
||||||
|
|
||||||
const addCartLoadingBtn = ref(false);
|
const addCartLoadingBtn = ref(false);
|
||||||
const routeId = ref(null);
|
const routeId = ref(null);
|
||||||
|
|
Loading…
Reference in New Issue