diff --git a/app/api/transfer/[path]/route.ts b/app/api/transfer/[path]/route.ts index 60907e3..a9ed8fc 100644 --- a/app/api/transfer/[path]/route.ts +++ b/app/api/transfer/[path]/route.ts @@ -119,44 +119,52 @@ export async function POST(req: any) { }, }) } else if (!notJson) { - const data = await res.json() + try { + const data = await (res.headers + .get("Content-Type") + ?.includes("application/json") + ? res.json() + : res.text()) - if (isLogin) { - const header = await headers() - let clientIP = - header.get("x-forwarded-for")?.split(",")[0] || - req?.socket?.remoteAddress - // ip v6地址 - if (clientIP.startsWith("::")) { - clientIP = clientIP.slice(7) + if (isLogin) { + const header = await headers() + let clientIP = + header.get("x-forwarded-for")?.split(",")[0] || + req?.socket?.remoteAddress + // ip v6地址 + if (clientIP.startsWith("::")) { + clientIP = clientIP.slice(7) + } + const newData = await handleLoginData({ + clientIP: clientIP, + fingerprint: body.fingerprint, + data, + }) + return new NextResponse(JSON.stringify(newData), { + headers: { + "Content-Type": "application/json", + }, + }) } - const newData = await handleLoginData({ - clientIP: clientIP, - fingerprint: body.fingerprint, - data, - }) - return new NextResponse(JSON.stringify(newData), { + if (isRefresh) { + const newData = await handleRefreshToken({ + userData, + data, + }) + return new NextResponse(JSON.stringify(newData), { + headers: { + "Content-Type": "application/json", + }, + }) + } + return new NextResponse(JSON.stringify(data), { headers: { "Content-Type": "application/json", }, }) + } catch (err) { + return NextResponse.json({ error: err }, { status: 500 }) } - if (isRefresh) { - const newData = await handleRefreshToken({ - userData, - data, - }) - return new NextResponse(JSON.stringify(newData), { - headers: { - "Content-Type": "application/json", - }, - }) - } - return new NextResponse(JSON.stringify(data), { - headers: { - "Content-Type": "application/json", - }, - }) } else { return res } diff --git a/app/management/team/employee/components/EditUserModal.tsx b/app/management/team/employee/components/EditUserModal.tsx index 59b339d..7446e6f 100644 --- a/app/management/team/employee/components/EditUserModal.tsx +++ b/app/management/team/employee/components/EditUserModal.tsx @@ -1,82 +1,55 @@ "use client" -import { getUserGroupAll, userEditById } from "@/components/label/api/user" +import { userUpdateGroup } from "@/components/label/api/user" import { User } from "@/components/label/api/user/typing" import { Button, Group, Modal, Select, Stack, TextInput } from "@mantine/core" import { useForm } from "@mantine/form" import { notifications } from "@mantine/notifications" -import { useEffect, useMemo, useState } from "react" +import { useEffect, useState } from "react" interface ComponentProps { opened: boolean data: User.UserInfo | null + groupOpts: Array<{ label: string; value: string }> onCloseAction: (refresh?: boolean) => void } export default function EditUserModal({ opened, data, + groupOpts, onCloseAction, }: ComponentProps) { - const [groupOpts, setGroupOpts] = useState< - Array<{ label: string; value: string }> - >([]) const [submitting, setSubmitting] = useState(false) - const groupValueByName = useMemo(() => { - const map = new Map() - groupOpts.forEach((g) => map.set(g.label, g.value)) - return map - }, [groupOpts]) - const form = useForm({ initialValues: { name: "", group_uuid: "", - base_city: "", - work_status: "1", }, validate: { name: (v) => (v.trim() ? null : "请输入用户名"), group_uuid: (v) => (v ? null : "请选择组织"), - base_city: (v) => (v.trim() ? null : "请输入所在地"), - work_status: (v) => (v ? null : "请选择状态"), }, }) - useEffect(() => { - if (!opened) return - const run = async () => { - const res = await getUserGroupAll() - setGroupOpts(res ?? []) - } - queueMicrotask(run) - }, [opened]) - useEffect(() => { if (!opened || !data) return form.setValues({ name: data.name ?? "", - group_uuid: groupValueByName.get(data.group_name ?? "") ?? "", - base_city: data.base_city ?? "", - work_status: data.work_status === 0 ? "0" : "1", + group_uuid: data.group_uuid ?? "", }) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [opened, data, groupValueByName]) + }, [opened, data]) const submit = form.onSubmit(async (values) => { if (!data?.uid) return try { setSubmitting(true) - await userEditById( - { - user_name: values.name.trim(), - group_uuid: values.group_uuid, - base_city: values.base_city.trim(), - work_status: Number(values.work_status), - }, - data.uid - ) + await userUpdateGroup({ + user_id: data.uid, + group_uuid: values.group_uuid, + }) notifications.show({ color: "green", title: "操作成功", @@ -120,24 +93,6 @@ export default function EditUserModal({ data={groupOpts} {...form.getInputProps("group_uuid")} /> - -