mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-02-05 13:10:08 +00:00
feat: 修改用户名,简化代码
This commit is contained in:
@@ -6,8 +6,8 @@ import {
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { Button, ButtonProps } from "@/components/ui/button"
|
||||
import { forwardRef, useState } from "react"
|
||||
import { useConfig } from "@/hooks/useConfig"
|
||||
import { ConfigEssential } from "@/types"
|
||||
import useSettings from "@/hooks/useSetting"
|
||||
import { ModelConfig } from "@/types"
|
||||
import { Check, Clipboard } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
@@ -21,15 +21,15 @@ enum OSTypes {
|
||||
|
||||
export const InstallCommandsMenu = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
|
||||
const [copy, setCopy] = useState(false);
|
||||
const { config } = useConfig();
|
||||
const settings = useSettings();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const switchState = async (type: number) => {
|
||||
if (!copy) {
|
||||
try {
|
||||
setCopy(true);
|
||||
if (config)
|
||||
await navigator.clipboard.writeText(generateCommand(type, config));
|
||||
if (settings)
|
||||
await navigator.clipboard.writeText(generateCommand(type, settings));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
toast(t("Error"), {
|
||||
@@ -60,7 +60,7 @@ export const InstallCommandsMenu = forwardRef<HTMLButtonElement, ButtonProps>((p
|
||||
);
|
||||
})
|
||||
|
||||
const generateCommand = (type: number, { agent_secret_key, install_host, listen_port, tls }: ConfigEssential) => {
|
||||
const generateCommand = (type: number, { agent_secret_key, install_host, listen_port, tls }: ModelConfig) => {
|
||||
if (!install_host)
|
||||
throw new Error("You have not specify the installed host.");
|
||||
|
||||
|
||||
@@ -32,22 +32,25 @@ import { useTranslation } from "react-i18next";
|
||||
const profileFormSchema = z.object({
|
||||
original_password: z.string().min(5).max(72),
|
||||
new_password: z.string().min(8).max(72),
|
||||
new_username: z.string().min(1).max(32),
|
||||
});
|
||||
|
||||
export const ProfileCard = ({ className }: { className: string }) => {
|
||||
const { t } = useTranslation();
|
||||
const { profile, setProfile } = useMainStore();
|
||||
|
||||
const form = useForm<z.infer<typeof profileFormSchema>>({
|
||||
resolver: zodResolver(profileFormSchema),
|
||||
defaultValues: {
|
||||
original_password: '',
|
||||
new_password: '',
|
||||
new_username: profile?.username,
|
||||
},
|
||||
resetOptions: {
|
||||
keepDefaultValues: false,
|
||||
}
|
||||
})
|
||||
|
||||
const { setProfile } = useMainStore();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const onSubmit = async (values: z.infer<typeof profileFormSchema>) => {
|
||||
@@ -69,18 +72,33 @@ export const ProfileCard = ({ className }: { className: string }) => {
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline" className={className}>
|
||||
{t("UpdatePassword")}
|
||||
{t("UpdateProfile")}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-xl">
|
||||
<ScrollArea className="max-h-[calc(100dvh-5rem)] p-3">
|
||||
<div className="items-center mx-1">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("UpdatePassword")}</DialogTitle>
|
||||
<DialogTitle>{t("UpdateProfile")}</DialogTitle>
|
||||
<DialogDescription />
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-2 my-2">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="new_username"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>{t("NewUsername")}</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="original_password"
|
||||
|
||||
Reference in New Issue
Block a user