temporary server action for group and inside
This commit is contained in:
@@ -7,14 +7,15 @@ type Props = {
|
||||
export default function IdComponent({ updateIdList }: Props) {
|
||||
const [idSet, setIdSet] = useState<Set<string>>(new Set());
|
||||
const onValidId = (id: string) => {
|
||||
setIdSet((prev) => new Set(prev.add(id)));
|
||||
const newSet = new Set(idSet.add(id));
|
||||
setIdSet(newSet);
|
||||
updateIdList([...newSet]);
|
||||
};
|
||||
const removeCid = (id: string) => {
|
||||
setIdSet((prev) => new Set([...prev].filter((x) => x !== id)));
|
||||
const newSet = new Set([...idSet].filter((x) => x !== id));
|
||||
setIdSet(newSet);
|
||||
updateIdList([...newSet]);
|
||||
};
|
||||
useEffect(() => {
|
||||
updateIdList([...idSet]);
|
||||
}, [idSet, updateIdList]);
|
||||
return (
|
||||
<div className="flex justify-center">
|
||||
<div className="flex flex-col gap-2">
|
||||
|
||||
5
app/inside/action.ts
Normal file
5
app/inside/action.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
"use server";
|
||||
|
||||
export async function saveUser(ids: string[]) {
|
||||
console.log(ids);
|
||||
} //TODO: submit inside user
|
||||
@@ -1,10 +1,14 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import { saveUser } from "./action";
|
||||
import IdComponent from "./IdComponent";
|
||||
|
||||
export default function Page() {
|
||||
const [idList, setIdList] = useState<string[]>([]);
|
||||
function submit() {} //TODO! submit inside user
|
||||
async function submit() {
|
||||
await saveUser(idList);
|
||||
alert("อัพเดทสำเร็จ");
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<IdComponent updateIdList={(cids) => setIdList(cids)} />
|
||||
|
||||
Reference in New Issue
Block a user