refactor: rename product to partyEvent in list page and view component
This commit is contained in:
@@ -98,26 +98,26 @@ export function useSearchProducts(query: string) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export async function createProduct(productData: IPartyEventItem) {
|
||||
export async function createPartyEvent(partyEventData: IPartyEventItem) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
const data = { productData };
|
||||
const data = { partyEventData };
|
||||
const {
|
||||
data: { id },
|
||||
} = await axiosInstance.post(endpoints.product.create, data);
|
||||
} = await axiosInstance.post(endpoints.partyEvent.create, data);
|
||||
|
||||
/**
|
||||
* Work in local
|
||||
*/
|
||||
mutate(
|
||||
endpoints.product.list,
|
||||
endpoints.partyEvent.list,
|
||||
(currentData: any) => {
|
||||
const currentProducts: IPartyEventItem[] = currentData?.products;
|
||||
const currentPartyEvents: IPartyEventItem[] = currentData?.partyEvents;
|
||||
|
||||
const products = [...currentProducts, { ...productData, id }];
|
||||
const partyEvents = [...currentPartyEvents, { ...partyEventData, id }];
|
||||
|
||||
return { ...currentData, products };
|
||||
return { ...currentData, partyEvents };
|
||||
},
|
||||
false
|
||||
);
|
||||
@@ -125,27 +125,27 @@ export async function createProduct(productData: IPartyEventItem) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export async function updateProduct(productData: Partial<IPartyEventItem>) {
|
||||
export async function updatePartyEvent(partyEventData: Partial<IPartyEventItem>) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
const data = { productData };
|
||||
await axiosInstance.put(endpoints.product.update, data);
|
||||
const data = { partyEventData };
|
||||
await axiosInstance.put(endpoints.partyEvent.update, data);
|
||||
|
||||
/**
|
||||
* Work in local
|
||||
*/
|
||||
|
||||
mutate(
|
||||
endpoints.product.list,
|
||||
endpoints.partyEvent.list,
|
||||
(currentData: any) => {
|
||||
const currentProducts: IPartyEventItem[] = currentData?.products;
|
||||
const currentPartyEvents: IPartyEventItem[] = currentData?.partyEvents;
|
||||
|
||||
const products = currentProducts.map((product) =>
|
||||
product.id === productData.id ? { ...product, ...productData } : product
|
||||
const partyEvents = currentPartyEvents.map((partyEvent) =>
|
||||
partyEvent.id === partyEventData.id ? { ...partyEvent, ...partyEventData } : partyEvent
|
||||
);
|
||||
|
||||
return { ...currentData, products };
|
||||
return { ...currentData, partyEvents };
|
||||
},
|
||||
false
|
||||
);
|
||||
@@ -153,26 +153,25 @@ export async function updateProduct(productData: Partial<IPartyEventItem>) {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export async function deletePartyEvent(productId: string) {
|
||||
export async function deletePartyEvent(partyEventId: string) {
|
||||
/**
|
||||
* Work on server
|
||||
*/
|
||||
const data = { productId };
|
||||
await axiosInstance.patch(endpoints.product.delete, data);
|
||||
const data = { partyEventId };
|
||||
await axiosInstance.patch(endpoints.partyEvent.delete, data);
|
||||
|
||||
/**
|
||||
* Work in local
|
||||
*/
|
||||
|
||||
mutate(
|
||||
endpoints.product.list,
|
||||
endpoints.partyEvent.list,
|
||||
(currentData: any) => {
|
||||
console.log({ currentData });
|
||||
const currentProducts: IPartyEventItem[] = currentData?.products;
|
||||
const currentProducts: IPartyEventItem[] = currentData?.partyEvents;
|
||||
|
||||
const products = currentProducts.filter((product) => product.id !== productId);
|
||||
const partyEvents = currentProducts.filter((partyEvent) => partyEvent.id !== partyEventId);
|
||||
|
||||
return { ...currentData, products };
|
||||
return { ...currentData, partyEvents };
|
||||
},
|
||||
false
|
||||
);
|
||||
|
Reference in New Issue
Block a user