Skip to content

Commit

Permalink
Merge 9f85317 into 1e1f45c
Browse files Browse the repository at this point in the history
  • Loading branch information
limivann authored Aug 27, 2024
2 parents 1e1f45c + 9f85317 commit 0dd4c89
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 85 deletions.
17 changes: 8 additions & 9 deletions apps/cms/src/@types/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

export class Order {
constructor(
public order_id = '',
public date = new Date(),
public order_person = '',
public image_url = '',
public item = '',
public qty = 0,
public size = '',
public colour = ''

public id = '',
public transaction_id = '',
public transaction_time = '',
public payment_method = '',
public customerEmail = '',
public status = '',
public updatedAt = '',
public createdAt = ''
) { }
}
50 changes: 20 additions & 30 deletions apps/cms/src/admin/views/MerchSales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ import ViewTemplate from "./ViewTemplate";
import { Column } from "payload/dist/admin/components/elements/Table/types";
import { Order } from "../../@types/Order";
import OrdersApi from "../../apis/orders.api";
import { IOrder } from "../../@types/IOrder";
import { RenderCellFactory } from "../utils/RenderCellFactory";
import SortedColumn from "../utils/SortedColumn";
import { Table } from "payload/dist/admin/components/elements/Table";
import { useHistory } from 'react-router-dom';

const MerchSales: AdminView = ({ user, canAccessAdmin }) => {
// Get data from API
const [data, setData] = useState<IOrder[]>(null);
const [data, setData] = useState<Order[]>(null);
const history = useHistory();
useEffect(() => {
OrdersApi.getOrders()
.then((res: IOrder[]) => setData(res))
.catch((error) => console.log(error));
const fetchOrders = async () => {
try {
const orders: Order[] = await OrdersApi.getOrders();
setData(orders);
} catch (error) {
console.error(error);
setData([]);
}
};
// eslint-disable-next-line @typescript-eslint/no-floating-promises
fetchOrders();
}, []);

// Output human-readable table headers based on the attribute names from the API
Expand Down Expand Up @@ -64,8 +73,8 @@ const MerchSales: AdminView = ({ user, canAccessAdmin }) => {
accessor: "edit",
components: {
Heading: <div>Edit</div>,
renderCell: ({ children }) => (
<Button onClick={() => handleEdit(children as string)}>Edit</Button>
renderCell: (data: Order) => (
<Button onClick={() => handleEdit(data)}>Edit</Button>
),
},
label: "Edit",
Expand All @@ -75,31 +84,12 @@ const MerchSales: AdminView = ({ user, canAccessAdmin }) => {

tableCols.push(editColumn);

const deleteColumn: Column = {
accessor: "delete",
components: {
Heading: <div>Delete</div>,
renderCell: ({ children }) => (
<Button onClick={() => handleDelete(children as string)}>Delete</Button>
),
},
label: "Delete",
name: "delete",
active: true,
const handleEdit = (data: Order) => {
const orderId = data.id;
// Navigate to edit
history.push(`/admin/collections/orders/${orderId}`)
};

tableCols.push(deleteColumn);

const handleEdit = (orderId: string) => {
console.log(`Dummy. Order ID: ${orderId}`);
};

const handleDelete = (orderId: string) => {
console.log(`Dummy. Order ID: ${orderId}`);
};

console.log(tableCols);

return (
<ViewTemplate
user={user}
Expand Down
53 changes: 8 additions & 45 deletions apps/cms/src/apis/orders.api.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,13 @@
import { IOrder } from "../@types/IOrder";
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/require-await */
import { Order } from "../@types/Order";

// todo turn into real api
class OrdersApi {
// eslint-disable-next-line @typescript-eslint/require-await
async getOrders(): Promise<IOrder[]> {
const res: IOrder[] = [];
const item1: IOrder = {
colour: "black",
date: new Date("2022-01-31"),
image_url:
"https://i.kym-cdn.com/entries/icons/original/000/033/421/cover2.jpg",
item: "graduation hat",
order_id: "1",
order_person: "kenneth west",
qty: 2,
size: "M",
};
res.push(item1);

const item2: IOrder = {
colour: "white",
date: new Date("2022-02-13"),
image_url:
"https://i.kym-cdn.com/photos/images/newsfeed/002/164/493/b8b.jpg",
item: "scorpion",
order_id: "2",
order_person: "aubrey graham drake",
qty: 1,
size: "L",
};
res.push(item2);

const item3: IOrder = {
colour: "beige",
date: new Date("2010-02-13"),
image_url:
"https://i.pinimg.com/474x/c0/f9/f1/c0f9f10a0061a8dd1080d7d9e560579c.jpg",
item: "dat stick",
order_id: "3",
order_person: "rich brian",
qty: 1,
size: "S",
};
res.push(item3);

return res;
async getOrders(): Promise<Order[]> {
const req = await fetch(`${process.env.PAYLOAD_PUBLIC_SERVER_URL}/api/orders`);
const orders = await req.json();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return orders?.docs as Order[];
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/web/features/merch/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Api {
return new Promise((res, rej) => {
setTimeout(() => {
res({
disabled: true,
disabled: false,
displayText:
"We are currently preparing for the next merch sale. Please look forward to our email!",
});
Expand Down

0 comments on commit 0dd4c89

Please sign in to comment.