This commit is contained in:
@@ -2,12 +2,19 @@ import { db } from "@/src/db";
|
||||
import LocationSelector from "../../components/LocationSelector";
|
||||
import LocationContextProvider from "@/components/locationContext";
|
||||
import GroupCreator from "./GroupCreator";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { user } from "@/src/schema";
|
||||
|
||||
export default async function Page() {
|
||||
const provinces = await db.query.province
|
||||
.findMany({ with: { zones: true } })
|
||||
.execute();
|
||||
const jobList = await db.query.group.findMany().execute();
|
||||
let r = await db.query.user
|
||||
.findMany({ columns: { id: true }, where: eq(user.verified, true) })
|
||||
.execute()
|
||||
.then((v) => v.length);
|
||||
console.log(r);
|
||||
return (
|
||||
<LocationContextProvider>
|
||||
<LocationSelector provinces={provinces} />
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
"use server";
|
||||
import { db } from "@/src/db";
|
||||
import { user } from "@/src/schema";
|
||||
import { inArray } from "drizzle-orm";
|
||||
|
||||
export async function saveUser(ids: string[]) {
|
||||
console.log(ids);
|
||||
} //TODO: submit inside user
|
||||
export async function saveUser(cids: string[]) {
|
||||
let rs = await db
|
||||
.update(user)
|
||||
.set({ verified: true })
|
||||
.where(inArray(user.cid, cids))
|
||||
.execute();
|
||||
return rs;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import IdComponent from "./IdComponent";
|
||||
export default function Page() {
|
||||
const [idList, setIdList] = useState<string[]>([]);
|
||||
async function submit() {
|
||||
await saveUser(idList);
|
||||
alert("อัพเดทสำเร็จ");
|
||||
let rs = await saveUser(idList);
|
||||
alert(`อัพเดทสำเร็จ ${rs.changes} คน`);
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
|
||||
47
app/total/TotalSetter.tsx
Normal file
47
app/total/TotalSetter.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
"use client";
|
||||
|
||||
import { LocationContext } from "@/components/locationContext";
|
||||
import { useContext, useState } from "react";
|
||||
import { updateZone } from "./action";
|
||||
|
||||
export default function TotalSetter() {
|
||||
const locationContext = useContext(LocationContext);
|
||||
const [total, setTotal] = useState<number>(0);
|
||||
async function submit() {
|
||||
if (
|
||||
locationContext?.zone[0] == undefined ||
|
||||
locationContext?.province[0] == undefined
|
||||
) {
|
||||
alert("ยังไม่ได้เลือกพื้นที่");
|
||||
return;
|
||||
}
|
||||
await updateZone(
|
||||
locationContext.province[0],
|
||||
locationContext.zone[0],
|
||||
total,
|
||||
);
|
||||
alert(`อัพเดทสำเร็จ`);
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<div className="flex">
|
||||
จำนวนทั้งหมด:{" "}
|
||||
<input
|
||||
value={total}
|
||||
className="rounded-md border-2"
|
||||
type="number"
|
||||
onChange={(e) =>
|
||||
setTotal(
|
||||
e.currentTarget.value !== ""
|
||||
? parseInt(e.currentTarget.value)
|
||||
: 0,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<button className="rounded-md bg-green-300 p-2" onClick={submit}>
|
||||
ยืนยัน
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
20
app/total/action.ts
Normal file
20
app/total/action.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
"use server";
|
||||
|
||||
export type JobCategory = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type Group = {
|
||||
id: number;
|
||||
jobs: number[];
|
||||
};
|
||||
|
||||
//TODO: submit group
|
||||
export async function updateZone(
|
||||
province: number,
|
||||
zone: number,
|
||||
total: number,
|
||||
) {
|
||||
console.log({ province, zone, total });
|
||||
}
|
||||
24
app/total/page.tsx
Normal file
24
app/total/page.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { db } from "@/src/db";
|
||||
import LocationSelector from "../../components/LocationSelector";
|
||||
import LocationContextProvider from "@/components/locationContext";
|
||||
import TotalSetter from "./TotalSetter";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { user } from "@/src/schema";
|
||||
|
||||
export default async function Page() {
|
||||
const provinces = await db.query.province
|
||||
.findMany({ with: { zones: true } })
|
||||
.execute();
|
||||
const jobList = await db.query.group.findMany().execute();
|
||||
let r = await db.query.user
|
||||
.findMany({ columns: { id: true }, where: eq(user.verified, true) })
|
||||
.execute()
|
||||
.then((v) => v.length);
|
||||
console.log(r);
|
||||
return (
|
||||
<LocationContextProvider>
|
||||
<LocationSelector provinces={provinces} />
|
||||
<TotalSetter />
|
||||
</LocationContextProvider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user