refactor: rename product to party-event across frontend modules and types
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//
|
||||
import { useMemo } from 'react';
|
||||
import axiosInstance, { endpoints, fetcher } from 'src/lib/axios';
|
||||
import type { IProductItem } from 'src/types/party-event';
|
||||
import type { IPartyEventItem } from 'src/types/party-event';
|
||||
import type { SWRConfiguration } from 'swr';
|
||||
import useSWR, { mutate } from 'swr';
|
||||
|
||||
@@ -16,24 +16,28 @@ const swrOptions: SWRConfiguration = {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
type ProductsData = {
|
||||
products: IProductItem[];
|
||||
type PartyEventsData = {
|
||||
partyEvents: IPartyEventItem[];
|
||||
};
|
||||
|
||||
export function useGetProducts() {
|
||||
const url = endpoints.product.list;
|
||||
export function useGetPartyEvents() {
|
||||
const url = endpoints.partyEvent.list;
|
||||
|
||||
const { data, isLoading, error, isValidating } = useSWR<ProductsData>(url, fetcher, swrOptions);
|
||||
const { data, isLoading, error, isValidating } = useSWR<PartyEventsData>(
|
||||
url,
|
||||
fetcher,
|
||||
swrOptions
|
||||
);
|
||||
|
||||
const memoizedValue = useMemo(
|
||||
() => ({
|
||||
products: data?.products || [],
|
||||
productsLoading: isLoading,
|
||||
productsError: error,
|
||||
productsValidating: isValidating,
|
||||
productsEmpty: !isLoading && !isValidating && !data?.products.length,
|
||||
partyEvents: data?.partyEvents || [],
|
||||
partyEventsLoading: isLoading,
|
||||
partyEventsError: error,
|
||||
partyEventsValidating: isValidating,
|
||||
partyEventsEmpty: !isLoading && !isValidating && !data?.partyEvents.length,
|
||||
}),
|
||||
[data?.products, error, isLoading, isValidating]
|
||||
[data?.partyEvents, error, isLoading, isValidating]
|
||||
);
|
||||
|
||||
return memoizedValue;
|
||||
@@ -42,7 +46,7 @@ export function useGetProducts() {
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
type ProductData = {
|
||||
product: IProductItem;
|
||||
product: IPartyEventItem;
|
||||
};
|
||||
|
||||
export function useGetPartyEvent(productId: string) {
|
||||
@@ -67,7 +71,7 @@ export function useGetPartyEvent(productId: string) {
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
type SearchResultsData = {
|
||||
results: IProductItem[];
|
||||
results: IPartyEventItem[];
|
||||
};
|
||||
|
||||
export function useSearchProducts(query: string) {
|
||||
@@ -94,7 +98,7 @@ export function useSearchProducts(query: string) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export async function createProduct(productData: IProductItem) {
|
||||
export async function createProduct(productData: IPartyEventItem) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
@@ -109,7 +113,7 @@ export async function createProduct(productData: IProductItem) {
|
||||
mutate(
|
||||
endpoints.product.list,
|
||||
(currentData: any) => {
|
||||
const currentProducts: IProductItem[] = currentData?.products;
|
||||
const currentProducts: IPartyEventItem[] = currentData?.products;
|
||||
|
||||
const products = [...currentProducts, { ...productData, id }];
|
||||
|
||||
@@ -121,7 +125,7 @@ export async function createProduct(productData: IProductItem) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export async function updateProduct(productData: Partial<IProductItem>) {
|
||||
export async function updateProduct(productData: Partial<IPartyEventItem>) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
@@ -135,7 +139,7 @@ export async function updateProduct(productData: Partial<IProductItem>) {
|
||||
mutate(
|
||||
endpoints.product.list,
|
||||
(currentData: any) => {
|
||||
const currentProducts: IProductItem[] = currentData?.products;
|
||||
const currentProducts: IPartyEventItem[] = currentData?.products;
|
||||
|
||||
const products = currentProducts.map((product) =>
|
||||
product.id === productData.id ? { ...product, ...productData } : product
|
||||
@@ -149,7 +153,7 @@ export async function updateProduct(productData: Partial<IProductItem>) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export async function deleteProduct(productId: string) {
|
||||
export async function deletePartyEvent(productId: string) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
@@ -164,7 +168,7 @@ export async function deleteProduct(productId: string) {
|
||||
endpoints.product.list,
|
||||
(currentData: any) => {
|
||||
console.log({ currentData });
|
||||
const currentProducts: IProductItem[] = currentData?.products;
|
||||
const currentProducts: IPartyEventItem[] = currentData?.products;
|
||||
|
||||
const products = currentProducts.filter((product) => product.id !== productId);
|
||||
|
||||
|
Reference in New Issue
Block a user