Skip to content

Commit 21fef32

Browse files
tuandddtoanbku
authored andcommitted
feat: distribute ads (#31)
* feat: distribute ads * feat: implement list ads * chore: enable sort icon --------- Co-authored-by: Toan Ho <[email protected]>
1 parent 1c60f7a commit 21fef32

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

components/pages/dashboard/ads/AdsForm.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export function AdsForm() {
228228
size: 'sm',
229229
className: 'md:px-3.5 md:py-2',
230230
})}
231+
onClick={back}
231232
>
232233
Back
233234
</button>
@@ -238,6 +239,7 @@ export function AdsForm() {
238239
size: 'sm',
239240
className: 'md:px-3.5 md:py-2',
240241
})}
242+
onClick={back}
241243
>
242244
Cancel
243245
</button>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { Switch } from '~components/Dashboard/Switch'
2+
import { Icon } from '@iconify/react'
3+
import { button } from '~components/Dashboard/Button'
4+
import { Table } from '~components/Dashboard/Table'
5+
6+
type Ads = {
7+
adName: string
8+
budget: 'Free' | 'Premium'
9+
schedule: 'Ongoing' | 'End'
10+
publish: boolean
11+
}
12+
13+
export default function ListAds() {
14+
const mockData: Ads[] = [
15+
{
16+
adName: 'Ad name',
17+
budget: 'Free',
18+
schedule: 'Ongoing',
19+
publish: true,
20+
},
21+
{
22+
adName: 'Ad name',
23+
budget: 'Free',
24+
schedule: 'End',
25+
publish: true,
26+
},
27+
{
28+
adName: 'Ad name',
29+
budget: 'Premium',
30+
schedule: 'Ongoing',
31+
publish: false,
32+
},
33+
]
34+
35+
return (
36+
<>
37+
<div className="overflow-auto">
38+
<Table
39+
data={mockData}
40+
columns={[
41+
{
42+
Header: 'Name',
43+
accessor: 'adName',
44+
width: 300,
45+
tdClassName: 'font-bold pl-4', // add padding left for first col
46+
Cell: ({ cell: { value } }: any) => {
47+
return <div>{value}</div>
48+
},
49+
},
50+
{
51+
Header: 'Budget',
52+
accessor: 'budget',
53+
Cell: ({ cell: { value }, row: { original } }: any) => {
54+
return (
55+
<span
56+
className={!original.publish ? 'text-dashboard-gray-8' : ''}
57+
>
58+
{value}
59+
</span>
60+
)
61+
},
62+
},
63+
{
64+
Header: 'Schedule',
65+
accessor: 'schedule',
66+
defaultCanSort: true,
67+
Cell: ({ cell: { value }, row: { original } }: any) => {
68+
return (
69+
<span
70+
className={!original.publish ? 'text-dashboard-gray-8' : ''}
71+
>
72+
{value}
73+
</span>
74+
)
75+
},
76+
},
77+
{
78+
Header: 'Publish',
79+
accessor: 'publish',
80+
thClassName: 'text-right',
81+
tdClassName: 'justify-end gap-2 pr-4', // add padding right for last col
82+
Cell: ({ cell: { value } }: any) => (
83+
<>
84+
<div className="flex gap-2 opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto transition">
85+
<button
86+
type="button"
87+
className={button({
88+
appearance: 'tertiary',
89+
size: 'icon',
90+
})}
91+
>
92+
<Icon className="w-4 h-4" icon="mingcute:pencil-fill" />
93+
</button>
94+
<button
95+
type="button"
96+
className={button({
97+
appearance: 'tertiary',
98+
size: 'icon',
99+
})}
100+
>
101+
<Icon className="w-4 h-4" icon="mingcute:delete-fill" />
102+
</button>
103+
</div>
104+
<Switch checked={value} />
105+
</>
106+
),
107+
},
108+
]}
109+
tableClassName="!overflow-visible"
110+
theadClassName="mb-2 text-xs font-bold uppercase thead text-dashboard-gray-2"
111+
tdClassName="flex items-center"
112+
trBodyClassName="py-4 bg-[#FFFFFF] rounded-lg border border-[#FFFFFF] hover:shadow hover:border-dashboard-gray-1 text-sm mb-2 transition group"
113+
/>
114+
</div>
115+
</>
116+
)
117+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"scripts": {
55
"proxy-ssl": "local-ssl-proxy --config proxy-config.json",
66
"dev:https": "(trap 'kill 0' SIGINT; yarn proxy-ssl & next dev -p 3001)",
7+
"dev": "next dev",
78
"build": "next build",
89
"start": "next start",
910
"type-check": "tsc",

pages/dashboard/[server_id]/ads/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useRouter } from 'next/router'
44
import React from 'react'
55
import { button } from '~components/Dashboard/Button'
66
import DashboardLayout from '~components/Dashboard/Layout'
7+
import ListAds from '~components/pages/dashboard/ads/ListAds'
78

89
const Ads = () => {
910
const { query } = useRouter()
@@ -27,7 +28,7 @@ const Ads = () => {
2728
</Link>
2829
}
2930
>
30-
ads page
31+
<ListAds />
3132
</DashboardLayout>
3233
)
3334
}

0 commit comments

Comments
 (0)