Skip to content

Commit 668e52b

Browse files
committed
Import Promotion class from types
1 parent b091f17 commit 668e52b

File tree

5 files changed

+20
-25
lines changed

5 files changed

+20
-25
lines changed

apps/cms/src/@types/IPromotion.ts

-3
This file was deleted.

apps/cms/src/@types/Promotion.ts

-8
This file was deleted.

apps/cms/src/admin/views/MerchPromotion.tsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ import { Button } from "payload/components/elements";
33
import { AdminView } from "payload/config";
44
import ViewTemplate from "./ViewTemplate";
55
import { Column } from "payload/dist/admin/components/elements/Table/types";
6-
import { Promotion } from "../../@types/Promotion";
7-
import { IPromotion } from "../../@types/IPromotion";
6+
import { PromoInfo } from "types";
87
import PromotionsApi from "../../apis/promotions.api";
98
import { RenderCellFactory } from "../utils/RenderCellFactory";
109
import SortedColumn from "../utils/SortedColumn";
1110
import { Table } from "payload/dist/admin/components/elements/Table";
1211

1312
const MerchPromotion: AdminView = ({ user, canAccessAdmin }) => {
1413
// Get data from API
15-
const [data, setData] = useState<IPromotion[]>(null);
14+
const [data, setData] = useState<PromoInfo[]>(null);
1615
useEffect(() => {
1716
PromotionsApi.getPromotions()
18-
.then((res: IPromotion[]) => setData(res))
17+
.then((res: PromoInfo[]) => setData(res))
1918
.catch((error) => console.log(error));
2019
}, []);
2120

@@ -34,7 +33,9 @@ const MerchPromotion: AdminView = ({ user, canAccessAdmin }) => {
3433
}
3534

3635
const tableCols = new Array<Column>();
37-
for (const key of Object.keys(new Promotion())) {
36+
const samplePromo = data[0];
37+
const keys = Object.keys(samplePromo);
38+
for (const key of keys) {
3839
const renderCellComponent = RenderCellFactory.get(data[0], key);
3940
const renderCell: React.FC<{ children?: React.ReactNode }> =
4041
renderCellComponent instanceof Promise
@@ -118,9 +119,7 @@ const MerchPromotion: AdminView = ({ user, canAccessAdmin }) => {
118119
</Button>
119120
<div
120121
style={{
121-
position: "absolute",
122-
top: 0,
123-
right: 0,
122+
position: "relative",
124123
}}
125124
>
126125
<Button onClick={handleCreatePromotion} buttonStyle="primary">

apps/cms/src/apis/promotions.api.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { IPromotion } from "../@types/IPromotion";
2-
1+
import { PromoInfo } from "types";
32
// todo turn into real api
43
class OrdersApi {
54
// eslint-disable-next-line @typescript-eslint/require-await
6-
async getPromotions(): Promise<IPromotion[]> {
7-
const res: IPromotion[] = [];
8-
const item1: IPromotion = {
5+
async getPromotions(): Promise<PromoInfo[]> {
6+
const res: PromoInfo[] = [];
7+
const item1: PromoInfo = {
98
promotion_id: "1",
109
name: "March Sales",
1110
discount_percentage: "10%",
1211
category: "T-shirts",
1312
};
1413
res.push(item1);
1514

16-
const item2: IPromotion = {
15+
const item2: PromoInfo = {
1716
promotion_id: "2",
1817
name: "Summer Sales",
1918
discount_percentage: "10%",

packages/types/src/lib/merch.ts

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ export interface Promotion {
8585
}>;
8686
}
8787

88+
export interface PromoInfo {
89+
90+
promotion_id: string;
91+
name: string;
92+
discount_percentage: string;
93+
category: string;
94+
};
95+
8896
export type PricedCart = {
8997
promoCode?: string;
9098
subtotal: number;

0 commit comments

Comments
 (0)