fix: edit users
This commit is contained in:
parent
995a5db0b4
commit
dd2344a59f
|
|
@ -124,18 +124,18 @@ interface RoleData {
|
||||||
}
|
}
|
||||||
|
|
||||||
const FormSchema = z.object({
|
const FormSchema = z.object({
|
||||||
level: z.string({
|
// level: z.string({
|
||||||
required_error: "Required",
|
// required_error: "Required",
|
||||||
}),
|
// }),
|
||||||
fullname: z.string({
|
fullname: z.string({
|
||||||
required_error: "Required",
|
required_error: "Required",
|
||||||
}),
|
}),
|
||||||
username: z.string({
|
username: z.string({
|
||||||
required_error: "Required",
|
required_error: "Required",
|
||||||
}),
|
}),
|
||||||
role: z.string({
|
// role: z.string({
|
||||||
required_error: "Required",
|
// required_error: "Required",
|
||||||
}),
|
// }),
|
||||||
// nrp: z.string({
|
// nrp: z.string({
|
||||||
// required_error: "Required",
|
// required_error: "Required",
|
||||||
// }),
|
// }),
|
||||||
|
|
@ -170,7 +170,6 @@ export default function EditUserForm() {
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
const levelName = getCookiesDecrypt("ulnae");
|
const levelName = getCookiesDecrypt("ulnae");
|
||||||
const [roleList, setRoleList] = useState<RoleData[]>([]);
|
const [roleList, setRoleList] = useState<RoleData[]>([]);
|
||||||
|
|
||||||
const [userEducations, setUserEducations] = useState<any>();
|
const [userEducations, setUserEducations] = useState<any>();
|
||||||
const [userSchools, setUserSchools] = useState<any>();
|
const [userSchools, setUserSchools] = useState<any>();
|
||||||
const [userCompetencies, setUserCompetencies] = useState<any>();
|
const [userCompetencies, setUserCompetencies] = useState<any>();
|
||||||
|
|
@ -189,7 +188,6 @@ export default function EditUserForm() {
|
||||||
|
|
||||||
const passwordVal = form.watch("password");
|
const passwordVal = form.watch("password");
|
||||||
const confPasswordVal = form.watch("confirmPassword");
|
const confPasswordVal = form.watch("confirmPassword");
|
||||||
const selectedRole = form.watch("role");
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getDataAdditional();
|
getDataAdditional();
|
||||||
|
|
@ -198,12 +196,8 @@ export default function EditUserForm() {
|
||||||
|
|
||||||
const initData = async () => {
|
const initData = async () => {
|
||||||
loading();
|
loading();
|
||||||
|
|
||||||
// 1️⃣ Ambil level dulu
|
|
||||||
const levels = await initFetch();
|
const levels = await initFetch();
|
||||||
console.log("LEVEL READY:", levels);
|
console.log("LEVEL READY:", levels);
|
||||||
|
|
||||||
// 2️⃣ Ambil user
|
|
||||||
const response = await getUserById(String(id));
|
const response = await getUserById(String(id));
|
||||||
close();
|
close();
|
||||||
|
|
||||||
|
|
@ -225,8 +219,8 @@ export default function EditUserForm() {
|
||||||
address: user.address ?? "",
|
address: user.address ?? "",
|
||||||
phoneNumber: user.phoneNumber ?? "",
|
phoneNumber: user.phoneNumber ?? "",
|
||||||
// nrp: user.identityNumber ?? "",
|
// nrp: user.identityNumber ?? "",
|
||||||
level: String(user.userLevelId),
|
// level: String(user.userLevelId),
|
||||||
role: String(user.userRoleId ?? ""),
|
// role: String(user.userRoleId ?? ""),
|
||||||
password: "",
|
password: "",
|
||||||
confirmPassword: "",
|
confirmPassword: "",
|
||||||
sns: [],
|
sns: [],
|
||||||
|
|
@ -281,7 +275,7 @@ export default function EditUserForm() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
setRoleList(levelsArr);
|
setRoleList(levelsArr);
|
||||||
return levelsArr; // ⬅️ PENTING
|
return levelsArr;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getDataAdditional() {
|
async function getDataAdditional() {
|
||||||
|
|
@ -301,49 +295,6 @@ export default function EditUserForm() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const roles =
|
|
||||||
levelName == "MABES POLRI"
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
id: "ADM-ID",
|
|
||||||
name: "Admin",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "APP-ID",
|
|
||||||
name: "Approver",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "CON-ID",
|
|
||||||
name: "Kontributor",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "SPV-ID",
|
|
||||||
name: "Supervisor Feedback Center",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "OPT-ID",
|
|
||||||
name: "Operator Feedback Center",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "KKUR-ID",
|
|
||||||
name: "Koor Kurator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "KUR-ID",
|
|
||||||
name: "Kurator",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
{
|
|
||||||
id: "APP-ID",
|
|
||||||
name: "Approver",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "CON-ID",
|
|
||||||
name: "Kontributor",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
async function save(data: z.infer<typeof FormSchema>) {
|
async function save(data: z.infer<typeof FormSchema>) {
|
||||||
const req = {
|
const req = {
|
||||||
fullname: data.fullname,
|
fullname: data.fullname,
|
||||||
|
|
@ -351,8 +302,8 @@ export default function EditUserForm() {
|
||||||
email: data.email,
|
email: data.email,
|
||||||
address: data.address,
|
address: data.address,
|
||||||
phoneNumber: data.phoneNumber,
|
phoneNumber: data.phoneNumber,
|
||||||
userLevelId: Number(data.level),
|
// userLevelId: Number(data.level),
|
||||||
userRoleId: userRoleId,
|
// userRoleId: userRoleId,
|
||||||
};
|
};
|
||||||
|
|
||||||
// let req: any = {
|
// let req: any = {
|
||||||
|
|
@ -420,7 +371,7 @@ export default function EditUserForm() {
|
||||||
className="space-y-6 bg-white p-10 w-full"
|
className="space-y-6 bg-white p-10 w-full"
|
||||||
>
|
>
|
||||||
<p className="text-xl">Data User</p>
|
<p className="text-xl">Data User</p>
|
||||||
<FormField
|
{/* <FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="level"
|
name="level"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
|
|
@ -478,7 +429,7 @@ export default function EditUserForm() {
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/> */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="fullname"
|
name="fullname"
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ const BannerListTable = () => {
|
||||||
|
|
||||||
const [sorting, setSorting] = React.useState<SortingState>([]);
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
const [columnVisibility, setColumnVisibility] =
|
const [columnVisibility, setColumnVisibility] =
|
||||||
React.useState<VisibilityState>({});
|
React.useState<VisibilityState>({});
|
||||||
|
|
@ -44,7 +44,7 @@ const BannerListTable = () => {
|
||||||
pageIndex: 0,
|
pageIndex: 0,
|
||||||
pageSize: Number(showData),
|
pageSize: Number(showData),
|
||||||
});
|
});
|
||||||
const [getData, setGetData] = React.useState<any>([]);
|
const [getData, setGetData] = React.useState<any[]>([]);
|
||||||
const dataChange = searchParams?.get("dataChange");
|
const dataChange = searchParams?.get("dataChange");
|
||||||
|
|
||||||
const [page, setPage] = React.useState(1);
|
const [page, setPage] = React.useState(1);
|
||||||
|
|
@ -90,17 +90,38 @@ const BannerListTable = () => {
|
||||||
}, [page, showData]);
|
}, [page, showData]);
|
||||||
|
|
||||||
async function getListBanner() {
|
async function getListBanner() {
|
||||||
loading();
|
try {
|
||||||
let temp: any;
|
loading();
|
||||||
|
|
||||||
const response = await listBanner();
|
const response = await listBanner();
|
||||||
const data = response?.data?.data?.content;
|
|
||||||
console.log("banner", data);
|
|
||||||
setGetData(data);
|
|
||||||
|
|
||||||
close();
|
const data = Array.isArray(response?.data?.data?.content)
|
||||||
|
? response.data.data.content
|
||||||
|
: [];
|
||||||
|
|
||||||
|
console.log("banner", data);
|
||||||
|
|
||||||
|
setGetData(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching banner list:", error);
|
||||||
|
setGetData([]);
|
||||||
|
} finally {
|
||||||
|
close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async function getListBanner() {
|
||||||
|
// loading();
|
||||||
|
// let temp: any;
|
||||||
|
|
||||||
|
// const response = await listBanner();
|
||||||
|
// const data = response?.data?.data?.content;
|
||||||
|
// console.log("banner", data);
|
||||||
|
// setGetData(data);
|
||||||
|
|
||||||
|
// close();
|
||||||
|
// }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Table className="overflow-hidden mt-10">
|
<Table className="overflow-hidden mt-10">
|
||||||
|
|
@ -113,7 +134,7 @@ const BannerListTable = () => {
|
||||||
? null
|
? null
|
||||||
: flexRender(
|
: flexRender(
|
||||||
header.column.columnDef.header,
|
header.column.columnDef.header,
|
||||||
header.getContext()
|
header.getContext(),
|
||||||
)}
|
)}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
))}
|
))}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ const ContentListBanner = () => {
|
||||||
const [totalData, setTotalData] = React.useState<number>(1);
|
const [totalData, setTotalData] = React.useState<number>(1);
|
||||||
const [sorting, setSorting] = React.useState<SortingState>([]);
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
const [columnVisibility, setColumnVisibility] =
|
const [columnVisibility, setColumnVisibility] =
|
||||||
React.useState<VisibilityState>({});
|
React.useState<VisibilityState>({});
|
||||||
|
|
@ -60,7 +60,7 @@ const ContentListBanner = () => {
|
||||||
try {
|
try {
|
||||||
const res = await listDataMedia(0, "100", "", "", "");
|
const res = await listDataMedia(0, "100", "", "", "");
|
||||||
const banners = res?.data?.data?.content?.filter(
|
const banners = res?.data?.data?.content?.filter(
|
||||||
(item: any) => item.isBanner
|
(item: any) => item.isBanner,
|
||||||
);
|
);
|
||||||
setBannerCount(banners?.length || 0);
|
setBannerCount(banners?.length || 0);
|
||||||
|
|
||||||
|
|
@ -117,31 +117,67 @@ const ContentListBanner = () => {
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
try {
|
try {
|
||||||
loading();
|
loading();
|
||||||
|
|
||||||
const res = await listDataMedia(
|
const res = await listDataMedia(
|
||||||
page - 1,
|
page - 1,
|
||||||
showData,
|
showData,
|
||||||
searchQuery,
|
searchQuery,
|
||||||
categoryFilter?.sort().join(","),
|
categoryFilter?.sort().join(","),
|
||||||
statusFilter?.sort().join(",")
|
statusFilter?.sort().join(","),
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = res?.data?.data;
|
const rawData = res?.data?.data;
|
||||||
const contentData = data?.content;
|
|
||||||
|
const contentData = Array.isArray(rawData?.content)
|
||||||
|
? rawData.content
|
||||||
|
: [];
|
||||||
|
|
||||||
contentData.forEach((item: any, index: number) => {
|
contentData.forEach((item: any, index: number) => {
|
||||||
item.no = (page - 1) * Number(showData) + index + 1;
|
item.no = (page - 1) * Number(showData) + index + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("contentData : ", data);
|
|
||||||
|
|
||||||
setData(contentData);
|
setData(contentData);
|
||||||
setTotalData(data?.totalElements);
|
setTotalData(rawData?.totalElements ?? 0);
|
||||||
setTotalPage(data?.totalPages);
|
setTotalPage(rawData?.totalPages ?? 1);
|
||||||
|
|
||||||
close();
|
close();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching tasks:", error);
|
close();
|
||||||
|
console.error("Error fetching banner data:", error);
|
||||||
|
setData([]);
|
||||||
|
setTotalData(0);
|
||||||
|
setTotalPage(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async function fetchData() {
|
||||||
|
// try {
|
||||||
|
// loading();
|
||||||
|
// const res = await listDataMedia(
|
||||||
|
// page - 1,
|
||||||
|
// showData,
|
||||||
|
// searchQuery,
|
||||||
|
// categoryFilter?.sort().join(","),
|
||||||
|
// statusFilter?.sort().join(",")
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const data = res?.data?.data;
|
||||||
|
// const contentData = data?.content;
|
||||||
|
// contentData.forEach((item: any, index: number) => {
|
||||||
|
// item.no = (page - 1) * Number(showData) + index + 1;
|
||||||
|
// });
|
||||||
|
|
||||||
|
// console.log("contentData : ", data);
|
||||||
|
|
||||||
|
// setData(contentData);
|
||||||
|
// setTotalData(data?.totalElements);
|
||||||
|
// setTotalPage(data?.totalPages);
|
||||||
|
// close();
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error("Error fetching tasks:", error);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
getCategories();
|
getCategories();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
@ -176,7 +212,7 @@ const ContentListBanner = () => {
|
||||||
|
|
||||||
const handleSelect = (id: number) => {
|
const handleSelect = (id: number) => {
|
||||||
setSelectedItems((prev) =>
|
setSelectedItems((prev) =>
|
||||||
prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]
|
prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id],
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ const AdminTagTable = () => {
|
||||||
const [totalData, setTotalData] = React.useState<number>(1);
|
const [totalData, setTotalData] = React.useState<number>(1);
|
||||||
const [sorting, setSorting] = React.useState<SortingState>([]);
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
const [columnVisibility, setColumnVisibility] =
|
const [columnVisibility, setColumnVisibility] =
|
||||||
React.useState<VisibilityState>({});
|
React.useState<VisibilityState>({});
|
||||||
|
|
@ -95,24 +95,33 @@ const AdminTagTable = () => {
|
||||||
try {
|
try {
|
||||||
loading();
|
loading();
|
||||||
const response = await getTags();
|
const response = await getTags();
|
||||||
const data = response?.data?.data;
|
|
||||||
|
const data = Array.isArray(response?.data?.data)
|
||||||
|
? response.data.data
|
||||||
|
: [];
|
||||||
|
|
||||||
data.forEach((item: any, index: number) => {
|
data.forEach((item: any, index: number) => {
|
||||||
item.no = (page - 1) * 10 + index + 1;
|
item.no = (page - 1) * 10 + index + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
setDataTable(data);
|
setDataTable(data);
|
||||||
setTotalData(data?.length);
|
setTotalData(data.length);
|
||||||
setTotalPage(1);
|
setTotalPage(1);
|
||||||
close();
|
close();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching tasks:", error);
|
close();
|
||||||
|
console.error("Error fetching tags:", error);
|
||||||
|
setDataTable([]);
|
||||||
|
setTotalData(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full overflow-x-auto bg-white p-4 rounded-sm space-y-3">
|
<div className="w-full overflow-x-auto bg-white p-4 rounded-sm space-y-3">
|
||||||
<div className="flex justify-between mb-10 items-center">
|
<div className="flex justify-between mb-10 items-center">
|
||||||
<p className="text-xl font-medium text-default-900">{t("tags", { defaultValue: "Tags" })}</p>
|
<p className="text-xl font-medium text-default-900">
|
||||||
|
{t("tags", { defaultValue: "Tags" })}
|
||||||
|
</p>
|
||||||
<CreateFAQModal />
|
<CreateFAQModal />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -126,7 +135,7 @@ const AdminTagTable = () => {
|
||||||
? null
|
? null
|
||||||
: flexRender(
|
: flexRender(
|
||||||
header.column.columnDef.header,
|
header.column.columnDef.header,
|
||||||
header.getContext()
|
header.getContext(),
|
||||||
)}
|
)}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
))}
|
))}
|
||||||
|
|
@ -134,8 +143,8 @@ const AdminTagTable = () => {
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{table.getRowModel().rows?.length ? (
|
{table?.getRowModel()?.rows?.length ? (
|
||||||
table.getRowModel().rows.map((row) => (
|
table?.getRowModel()?.rows.map((row) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={row.id}
|
key={row.id}
|
||||||
data-state={row.getIsSelected() && "selected"}
|
data-state={row.getIsSelected() && "selected"}
|
||||||
|
|
|
||||||
28
lib/menus.ts
28
lib/menus.ts
|
|
@ -238,20 +238,20 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
||||||
icon: "heroicons:arrow-trending-up",
|
icon: "heroicons:arrow-trending-up",
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// href: "/admin/settings/tag",
|
href: "/admin/settings/tag",
|
||||||
// label: "Tag",
|
label: "Tag",
|
||||||
// active: pathname === "/admin/settings/tag",
|
active: pathname === "/admin/settings/tag",
|
||||||
// icon: "heroicons:arrow-trending-up",
|
icon: "heroicons:arrow-trending-up",
|
||||||
// children: [],
|
children: [],
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// href: "/admin/settings/banner",
|
href: "/admin/settings/banner",
|
||||||
// label: "Banner",
|
label: "Banner",
|
||||||
// active: pathname === "/admin/settings/banner",
|
active: pathname === "/admin/settings/banner",
|
||||||
// icon: "heroicons:arrow-trending-up",
|
icon: "heroicons:arrow-trending-up",
|
||||||
// children: [],
|
children: [],
|
||||||
// },
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue