**chore(storefront): apply consistent code formatting and improve readability**
Refactored multiple files for code styling consistency, using proper indentation and spacing to align with team standards. Improved readability and maintainability across composables, Apollo plugin, and localization files. Enhancements: - Standardized import and function indentation across all composables. - Updated `biome.json` schema to the latest version (v2.4.4) for tool compatibility. - Organized code blocks in Apollo plugin for better understandability. No functional changes introduced—this is a non-breaking, code refinement commit.
This commit is contained in:
parent
c36135d78d
commit
e65e7b7d73
18 changed files with 600 additions and 576 deletions
|
|
@ -31,7 +31,7 @@ export function useRegister() {
|
||||||
password: payload.password,
|
password: payload.password,
|
||||||
confirmPassword: payload.confirmPassword,
|
confirmPassword: payload.confirmPassword,
|
||||||
referrer: payload.referrer,
|
referrer: payload.referrer,
|
||||||
isSubscribed: payload.isSubscribed
|
isSubscribed: payload.isSubscribed,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result?.data?.createUser?.success) {
|
if (result?.data?.createUser?.success) {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export function useBrands(args: IBrandArgs = {}) {
|
||||||
endCursor: string;
|
endCursor: string;
|
||||||
}>({
|
}>({
|
||||||
hasNextPage: false,
|
hasNextPage: false,
|
||||||
endCursor: ''
|
endCursor: '',
|
||||||
});
|
});
|
||||||
const error = ref<string | null>(null);
|
const error = ref<string | null>(null);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ import {
|
||||||
} from '@graphql/mutations/cart';
|
} from '@graphql/mutations/cart';
|
||||||
import type {
|
import type {
|
||||||
IAddToOrderResponse,
|
IAddToOrderResponse,
|
||||||
IBulkOrderResponse, IProduct,
|
IBulkOrderResponse,
|
||||||
|
IProduct,
|
||||||
IRemoveAllFromOrderResponse,
|
IRemoveAllFromOrderResponse,
|
||||||
IRemoveFromOrderResponse,
|
IRemoveFromOrderResponse,
|
||||||
IRemoveKindFromOrderResponse,
|
IRemoveKindFromOrderResponse,
|
||||||
|
|
@ -168,17 +169,20 @@ export function useOrderOverwrite() {
|
||||||
switch (args.type) {
|
switch (args.type) {
|
||||||
case 'add': {
|
case 'add': {
|
||||||
const currentCart = cookieCart.value || [];
|
const currentCart = cookieCart.value || [];
|
||||||
const existingItem = currentCart.find(
|
const existingItem = currentCart.find((item) => item.product.uuid === args.product.uuid);
|
||||||
(item) => item.product.uuid === args.product.uuid
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existingItem) {
|
if (existingItem) {
|
||||||
existingItem.quantity += 1;
|
existingItem.quantity += 1;
|
||||||
cookieCart.value = [...currentCart];
|
cookieCart.value = [
|
||||||
|
...currentCart,
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
cookieCart.value = [
|
cookieCart.value = [
|
||||||
...currentCart,
|
...currentCart,
|
||||||
{ product: args.product, quantity: 1 }
|
{
|
||||||
|
product: args.product,
|
||||||
|
quantity: 1,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,18 +198,16 @@ export function useOrderOverwrite() {
|
||||||
|
|
||||||
case 'remove': {
|
case 'remove': {
|
||||||
const currentCart = cookieCart.value || [];
|
const currentCart = cookieCart.value || [];
|
||||||
const existingItem = currentCart.find(
|
const existingItem = currentCart.find((item) => item.product.uuid === args.product.uuid);
|
||||||
(item) => item.product.uuid === args.product.uuid
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existingItem) {
|
if (existingItem) {
|
||||||
if (existingItem.quantity > 1) {
|
if (existingItem.quantity > 1) {
|
||||||
existingItem.quantity -= 1;
|
existingItem.quantity -= 1;
|
||||||
cookieCart.value = [...currentCart];
|
cookieCart.value = [
|
||||||
|
...currentCart,
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
cookieCart.value = currentCart.filter(
|
cookieCart.value = currentCart.filter((item) => item.product.uuid !== args.product.uuid);
|
||||||
(item) => item.product.uuid !== args.product.uuid
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useNotification({
|
useNotification({
|
||||||
|
|
@ -220,9 +222,7 @@ export function useOrderOverwrite() {
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'removeKind': {
|
case 'removeKind': {
|
||||||
cookieCart.value = cookieCart.value.filter(
|
cookieCart.value = cookieCart.value.filter((item) => item.product.uuid !== args.product.uuid);
|
||||||
(item) => item.product.uuid !== args.product.uuid
|
|
||||||
);
|
|
||||||
|
|
||||||
useNotification({
|
useNotification({
|
||||||
message: t('popup.success.removeFromCart', {
|
message: t('popup.success.removeFromCart', {
|
||||||
|
|
@ -247,10 +247,8 @@ export function useOrderOverwrite() {
|
||||||
|
|
||||||
case 'bulk': {
|
case 'bulk': {
|
||||||
if (args.bulkAction === 'remove' && args.products) {
|
if (args.bulkAction === 'remove' && args.products) {
|
||||||
const uuidsToRemove = args.products.map(p => p.uuid);
|
const uuidsToRemove = args.products.map((p) => p.uuid);
|
||||||
cookieCart.value = cookieCart.value.filter(
|
cookieCart.value = cookieCart.value.filter((item) => !uuidsToRemove.includes(item.product.uuid));
|
||||||
(item) => !uuidsToRemove.includes(item.product.uuid)
|
|
||||||
);
|
|
||||||
|
|
||||||
useNotification({
|
useNotification({
|
||||||
message: t('popup.success.bulkRemoveOrder'),
|
message: t('popup.success.bulkRemoveOrder'),
|
||||||
|
|
@ -260,16 +258,16 @@ export function useOrderOverwrite() {
|
||||||
const currentCart = cookieCart.value || [];
|
const currentCart = cookieCart.value || [];
|
||||||
|
|
||||||
for (const productRef of args.products) {
|
for (const productRef of args.products) {
|
||||||
const existingItem = currentCart.find(
|
const existingItem = currentCart.find((item) => item.product.uuid === productRef.uuid);
|
||||||
(item) => item.product.uuid === productRef.uuid
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existingItem) {
|
if (existingItem) {
|
||||||
existingItem.quantity += 1;
|
existingItem.quantity += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cookieCart.value = [...currentCart];
|
cookieCart.value = [
|
||||||
|
...currentCart,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,10 @@ export function useOrderSync() {
|
||||||
const apiCartProducts = cartStore.currentOrder?.orderProducts?.edges || [];
|
const apiCartProducts = cartStore.currentOrder?.orderProducts?.edges || [];
|
||||||
|
|
||||||
const apiProductMap = new Map(
|
const apiProductMap = new Map(
|
||||||
apiCartProducts.map(e => [e.node.product.uuid, e.node.quantity])
|
apiCartProducts.map((e) => [
|
||||||
|
e.node.product.uuid,
|
||||||
|
e.node.quantity,
|
||||||
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const productsToSync = [];
|
const productsToSync = [];
|
||||||
|
|
@ -40,7 +43,9 @@ export function useOrderSync() {
|
||||||
|
|
||||||
if (quantityDifference > 0) {
|
if (quantityDifference > 0) {
|
||||||
for (let i = 0; i < quantityDifference; i++) {
|
for (let i = 0; i < quantityDifference; i++) {
|
||||||
productsToSync.push({ uuid: cartItem.product.uuid });
|
productsToSync.push({
|
||||||
|
uuid: cartItem.product.uuid,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +60,7 @@ export function useOrderSync() {
|
||||||
type: 'bulk',
|
type: 'bulk',
|
||||||
bulkAction: 'add',
|
bulkAction: 'add',
|
||||||
isBulkSync: true,
|
isBulkSync: true,
|
||||||
products: productsToSync
|
products: productsToSync,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to sync cart:', err);
|
console.error('Failed to sync cart:', err);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {GET_POSTS} from "@graphql/queries/standalone/blog";
|
import { GET_POSTS } from '@graphql/queries/standalone/blog';
|
||||||
import type {IPostResponse} from '@types';
|
import type { IPostResponse } from '@types';
|
||||||
|
|
||||||
export function usePosts() {
|
export function usePosts() {
|
||||||
const { data, error } = useAsyncQuery<IPostResponse>(GET_POSTS);
|
const { data, error } = useAsyncQuery<IPostResponse>(GET_POSTS);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,15 @@ import type { Ref } from 'vue';
|
||||||
export function useFilters(filterableAttributes: Ref<IStoreFilters[]>) {
|
export function useFilters(filterableAttributes: Ref<IStoreFilters[]>) {
|
||||||
const selectedMap = reactive<Record<string, Record<string, boolean>>>({});
|
const selectedMap = reactive<Record<string, Record<string, boolean>>>({});
|
||||||
const selectedAllMap = reactive<Record<string, boolean>>({});
|
const selectedAllMap = reactive<Record<string, boolean>>({});
|
||||||
const priceRange = ref<[number, number]>([0, 50000]);
|
const priceRange = ref<
|
||||||
|
[
|
||||||
|
number,
|
||||||
|
number,
|
||||||
|
]
|
||||||
|
>([
|
||||||
|
0,
|
||||||
|
50000,
|
||||||
|
]);
|
||||||
const collapse = ref<string[]>([]);
|
const collapse = ref<string[]>([]);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -100,7 +108,10 @@ export function useFilters(filterableAttributes: Ref<IStoreFilters[]>) {
|
||||||
if (expr.startsWith('range-')) {
|
if (expr.startsWith('range-')) {
|
||||||
const parts = expr.slice(6).split('-');
|
const parts = expr.slice(6).split('-');
|
||||||
if (parts.length >= 2) {
|
if (parts.length >= 2) {
|
||||||
result[name] = [parts.slice(0, parts.length - 1).join('-'), parts[parts.length - 1]];
|
result[name] = [
|
||||||
|
parts.slice(0, parts.length - 1).join('-'),
|
||||||
|
parts[parts.length - 1],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
} else if (expr.startsWith('in-')) {
|
} else if (expr.startsWith('in-')) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ export function useAvatarUpload() {
|
||||||
context: {
|
context: {
|
||||||
hasUpload: true,
|
hasUpload: true,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDone(({ data }) => {
|
onDone(({ data }) => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { orderStatuses } from '@appConstants';
|
import { orderStatuses } from '@appConstants';
|
||||||
import { useOrderSync } from '@composables/orders';
|
import { useOrderSync } from '@composables/orders';
|
||||||
import {useWishlistSync} from "@composables/wishlist";
|
import { useWishlistSync } from '@composables/wishlist';
|
||||||
import { getUserBaseData } from '@graphql/queries/combined/userBaseData';
|
import { getUserBaseData } from '@graphql/queries/combined/userBaseData';
|
||||||
import type { IUserBaseDataResponse } from '@types';
|
import type { IUserBaseDataResponse } from '@types';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ import {
|
||||||
} from '@graphql/mutations/wishlist';
|
} from '@graphql/mutations/wishlist';
|
||||||
import type {
|
import type {
|
||||||
IAddToWishlistResponse,
|
IAddToWishlistResponse,
|
||||||
IBulkWishlistResponse, IProduct,
|
IBulkWishlistResponse,
|
||||||
|
IProduct,
|
||||||
IRemoveAllFromWishlistResponse,
|
IRemoveAllFromWishlistResponse,
|
||||||
IRemoveFromWishlistResponse,
|
IRemoveFromWishlistResponse,
|
||||||
} from '@types';
|
} from '@types';
|
||||||
|
|
@ -147,9 +148,7 @@ export function useWishlistOverwrite() {
|
||||||
} else {
|
} else {
|
||||||
switch (args.type) {
|
switch (args.type) {
|
||||||
case 'add': {
|
case 'add': {
|
||||||
const isAlreadyInWishlist = cookieWishlist.value.some(
|
const isAlreadyInWishlist = cookieWishlist.value.some((item) => item.uuid === args.product.uuid);
|
||||||
(item) => item.uuid === args.product.uuid
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isAlreadyInWishlist) {
|
if (isAlreadyInWishlist) {
|
||||||
useNotification({
|
useNotification({
|
||||||
|
|
@ -159,7 +158,10 @@ export function useWishlistOverwrite() {
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
cookieWishlist.value = [...cookieWishlist.value, args.product];
|
cookieWishlist.value = [
|
||||||
|
...cookieWishlist.value,
|
||||||
|
args.product,
|
||||||
|
];
|
||||||
|
|
||||||
useNotification({
|
useNotification({
|
||||||
message: t('popup.success.addToWishlist', {
|
message: t('popup.success.addToWishlist', {
|
||||||
|
|
@ -173,9 +175,7 @@ export function useWishlistOverwrite() {
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'remove': {
|
case 'remove': {
|
||||||
cookieWishlist.value = cookieWishlist.value.filter(
|
cookieWishlist.value = cookieWishlist.value.filter((item) => item.uuid !== args.product.uuid);
|
||||||
(item) => item.uuid !== args.product.uuid
|
|
||||||
);
|
|
||||||
|
|
||||||
useNotification({
|
useNotification({
|
||||||
message: t('popup.success.removeFromWishlist', {
|
message: t('popup.success.removeFromWishlist', {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import {useWishlistOverwrite} from "@composables/wishlist/useWishlistOverwrite";
|
import { useWishlistOverwrite } from '@composables/wishlist/useWishlistOverwrite';
|
||||||
|
|
||||||
export function useWishlistSync() {
|
export function useWishlistSync() {
|
||||||
const wishlistStore = useWishlistStore();
|
const wishlistStore = useWishlistStore();
|
||||||
|
|
@ -26,11 +26,9 @@ export function useWishlistSync() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiProductUuids = wishlistStore.wishlist?.products?.edges.map(e => e.node.uuid) || [];
|
const apiProductUuids = wishlistStore.wishlist?.products?.edges.map((e) => e.node.uuid) || [];
|
||||||
|
|
||||||
const productsToAdd = cookieProducts.filter(
|
const productsToAdd = cookieProducts.filter((product) => !apiProductUuids.includes(product.uuid));
|
||||||
(product) => !apiProductUuids.includes(product.uuid)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (productsToAdd.length === 0) {
|
if (productsToAdd.length === 0) {
|
||||||
cookieWishlist.value = [];
|
cookieWishlist.value = [];
|
||||||
|
|
@ -42,8 +40,10 @@ export function useWishlistSync() {
|
||||||
type: 'bulk',
|
type: 'bulk',
|
||||||
bulkAction: 'add',
|
bulkAction: 'add',
|
||||||
isBulkSync: true,
|
isBulkSync: true,
|
||||||
products: productsToAdd.map(p => ({ uuid: p.uuid }))
|
products: productsToAdd.map((p) => ({
|
||||||
})
|
uuid: p.uuid,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
if (bulkResult?.data?.bulkWishlistAction?.wishlist) {
|
if (bulkResult?.data?.bulkWishlistAction?.wishlist) {
|
||||||
wishlistStore.setWishlist(bulkResult.data.bulkWishlistAction.wishlist);
|
wishlistStore.setWishlist(bulkResult.data.bulkWishlistAction.wishlist);
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@ export enum docsSlugs {
|
||||||
FAQ = 'faq',
|
FAQ = 'faq',
|
||||||
SHIPPING = 'shipping-information',
|
SHIPPING = 'shipping-information',
|
||||||
RETURN = 'return-policy',
|
RETURN = 'return-policy',
|
||||||
ABOUT = 'about-us'
|
ABOUT = 'about-us',
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
|
|
||||||
import { ApolloLink, from } from '@apollo/client/core';
|
import { ApolloLink, from } from '@apollo/client/core';
|
||||||
import { setContext } from '@apollo/client/link/context';
|
import { setContext } from '@apollo/client/link/context';
|
||||||
import { onError } from '@apollo/client/link/error';
|
import { onError } from '@apollo/client/link/error';
|
||||||
import { provideApolloClient } from '@vue/apollo-composable';
|
import { provideApolloClient } from '@vue/apollo-composable';
|
||||||
import createUploadLink from "apollo-upload-client/createUploadLink.mjs";
|
import createUploadLink from 'apollo-upload-client/createUploadLink.mjs';
|
||||||
|
|
||||||
export default defineNuxtPlugin((nuxtApp) => {
|
export default defineNuxtPlugin((nuxtApp) => {
|
||||||
const runtime = useRuntimeConfig();
|
const runtime = useRuntimeConfig();
|
||||||
|
|
@ -22,23 +21,29 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||||
let locale = 'en-gb';
|
let locale = 'en-gb';
|
||||||
|
|
||||||
if (import.meta.client) {
|
if (import.meta.client) {
|
||||||
const clientCookies = document.cookie.split(';').reduce((acc, cookie) => {
|
const clientCookies = document.cookie.split(';').reduce(
|
||||||
|
(acc, cookie) => {
|
||||||
const [key, value] = cookie.trim().split('=');
|
const [key, value] = cookie.trim().split('=');
|
||||||
acc[key] = decodeURIComponent(value);
|
acc[key] = decodeURIComponent(value);
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, string>);
|
},
|
||||||
|
{} as Record<string, string>,
|
||||||
|
);
|
||||||
|
|
||||||
accessToken = clientCookies[$appHelpers.COOKIES_ACCESS_TOKEN_KEY] || '';
|
accessToken = clientCookies[$appHelpers.COOKIES_ACCESS_TOKEN_KEY] || '';
|
||||||
locale = clientCookies[$appHelpers.COOKIES_LOCALE_KEY] || 'en-gb';
|
locale = clientCookies[$appHelpers.COOKIES_LOCALE_KEY] || 'en-gb';
|
||||||
} else {
|
} else {
|
||||||
const cookieHeader = nuxtApp.ssrContext?.event?.node?.req?.headers?.cookie || '';
|
const cookieHeader = nuxtApp.ssrContext?.event?.node?.req?.headers?.cookie || '';
|
||||||
const serverCookies = cookieHeader.split(';').reduce((acc, cookie) => {
|
const serverCookies = cookieHeader.split(';').reduce(
|
||||||
|
(acc, cookie) => {
|
||||||
const [key, value] = cookie.trim().split('=');
|
const [key, value] = cookie.trim().split('=');
|
||||||
if (key && value) {
|
if (key && value) {
|
||||||
acc[key] = decodeURIComponent(value);
|
acc[key] = decodeURIComponent(value);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, string>);
|
},
|
||||||
|
{} as Record<string, string>,
|
||||||
|
);
|
||||||
|
|
||||||
accessToken = serverCookies[$appHelpers.COOKIES_ACCESS_TOKEN_KEY] || '';
|
accessToken = serverCookies[$appHelpers.COOKIES_ACCESS_TOKEN_KEY] || '';
|
||||||
locale = serverCookies[$appHelpers.COOKIES_LOCALE_KEY] || 'en-gb';
|
locale = serverCookies[$appHelpers.COOKIES_LOCALE_KEY] || 'en-gb';
|
||||||
|
|
@ -46,14 +51,16 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||||
|
|
||||||
const hdrs: Record<string, string> = {
|
const hdrs: Record<string, string> = {
|
||||||
...headers,
|
...headers,
|
||||||
'Accept-Language': locale
|
'Accept-Language': locale,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
hdrs['X-SCHON-AUTH'] = `Bearer ${accessToken}`;
|
hdrs['X-SCHON-AUTH'] = `Bearer ${accessToken}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { headers: hdrs };
|
return {
|
||||||
|
headers: hdrs,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const customLink = new ApolloLink((operation, forward) => {
|
const customLink = new ApolloLink((operation, forward) => {
|
||||||
|
|
@ -63,15 +70,17 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const httpLink = createUploadLink({
|
const httpLink = createUploadLink({
|
||||||
uri: `https://api.${runtime.public.schonBaseDomain}/graphql/`
|
uri: `https://api.${runtime.public.schonBaseDomain}/graphql/`,
|
||||||
});
|
});
|
||||||
|
|
||||||
$apollo.defaultClient.setLink(from([
|
$apollo.defaultClient.setLink(
|
||||||
|
from([
|
||||||
errorLink,
|
errorLink,
|
||||||
authLink,
|
authLink,
|
||||||
customLink,
|
customLink,
|
||||||
httpLink,
|
httpLink,
|
||||||
]));
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
provideApolloClient($apollo.defaultClient);
|
provideApolloClient($apollo.defaultClient);
|
||||||
});
|
});
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://biomejs.dev/schemas/2.3.8/schema.json",
|
"$schema": "https://biomejs.dev/schemas/2.4.4/schema.json",
|
||||||
"vcs": {
|
"vcs": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"clientKind": "git",
|
"clientKind": "git",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue