-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GL-26: Добавлены интеграции с сервисом текстур (скины и плащи)
- Loading branch information
Терентьев Вадим Алексеевич
committed
May 4, 2024
1 parent
81fd28d
commit e598931
Showing
13 changed files
with
249 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ConnectTexturesForm } from "@/features/connect-textures-form/ui/ConnectTexturesForm"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { z } from "zod"; | ||
|
||
export const ConnectTexturesSchema = z.object({ | ||
url_skins: z | ||
.string() | ||
.min(1, { message: "Вы не заполнили поле" }) | ||
.transform((v) => v.trim()), | ||
url_cloaks: z | ||
.string() | ||
.min(1, { message: "Вы не заполнили поле" }) | ||
.transform((v) => v.trim()), | ||
}); | ||
|
||
export type ConnectTexturesFormSchemaType = z.infer<typeof ConnectTexturesSchema>; |
106 changes: 106 additions & 0 deletions
106
src/features/connect-textures-form/ui/ConnectTexturesForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
|
||
import { Controller, useForm } from "react-hook-form"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
|
||
import { cn } from "@/shared/lib/utils"; | ||
import { Button } from "@/shared/ui/button"; | ||
import { Form, FormControl, FormItem, FormLabel, FormMessage } from "@/shared/ui/form"; | ||
import { Input } from "@/shared/ui/input"; | ||
import { TexturesServiceType } from "@/shared/enums"; | ||
import { useConnectTextures, useEditConnectTextures } from "@/shared/hooks"; | ||
import { Icons } from "@/shared/ui/icons"; | ||
|
||
import { ConnectTexturesFormSchemaType, ConnectTexturesSchema } from "../lib/static"; | ||
|
||
interface ConnectTexturesFormProps extends React.HTMLAttributes<HTMLDivElement> { | ||
onOpenChange: (open: boolean) => void; | ||
} | ||
|
||
export function ConnectTexturesForm({ | ||
className, | ||
onOpenChange, | ||
...props | ||
}: ConnectTexturesFormProps) { | ||
const { data: textures_skins } = useConnectTextures(TexturesServiceType.TEXTURES_SERVICE_SKINS); | ||
const { data: textures_cloaks } = useConnectTextures(TexturesServiceType.TEXTURES_SERVICE_CLOAKS); | ||
|
||
const { mutateAsync, isPending } = useEditConnectTextures(); | ||
|
||
const form = useForm<ConnectTexturesFormSchemaType>({ | ||
values: { | ||
url_skins: textures_skins?.url || "", | ||
url_cloaks: textures_cloaks?.url || "", | ||
}, | ||
resolver: zodResolver(ConnectTexturesSchema), | ||
}); | ||
|
||
const onSubmit = async (data: ConnectTexturesFormSchemaType) => { | ||
if (form.formState.dirtyFields.url_skins) { | ||
await mutateAsync({ | ||
type: TexturesServiceType.TEXTURES_SERVICE_SKINS, | ||
url: data.url_skins, | ||
}).then(() => { | ||
onOpenChange(false); | ||
}); | ||
} | ||
|
||
if (form.formState.dirtyFields.url_cloaks) { | ||
await mutateAsync({ | ||
type: TexturesServiceType.TEXTURES_SERVICE_CLOAKS, | ||
url: data.url_cloaks, | ||
}).then(() => { | ||
onOpenChange(false); | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={cn("grid gap-4", className)} {...props}> | ||
<Form {...form}> | ||
<form className="flex flex-col space-y-6" onSubmit={form.handleSubmit(onSubmit)}> | ||
<Controller | ||
control={form.control} | ||
name="url_skins" | ||
render={({ field }) => ( | ||
<FormItem className="flex-1"> | ||
<FormLabel>Введите URL к сервису скинов</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Введите URL к сервису скинов" {...field} /> | ||
</FormControl> | ||
{form.formState.errors.url_skins && ( | ||
<FormMessage>{form.formState.errors.url_skins.message}</FormMessage> | ||
)} | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<Controller | ||
control={form.control} | ||
name="url_cloaks" | ||
render={({ field }) => ( | ||
<FormItem className="flex-1"> | ||
<FormLabel>Введите URL к сервису плащей</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Введите URL к сервису плащей" {...field} /> | ||
</FormControl> | ||
{form.formState.errors.url_cloaks && ( | ||
<FormMessage>{form.formState.errors.url_cloaks.message}</FormMessage> | ||
)} | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<div className="flex justify-between items-center"> | ||
<Button className="w-fit ml-auto" disabled={isPending || !form.formState.isDirty}> | ||
{isPending && <Icons.spinner className="mr-2 h-4 w-4 animate-spin" />} | ||
Сохранить | ||
</Button> | ||
</div> | ||
</form> | ||
</Form> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './auth'; | ||
export * from './systems'; | ||
export * from "./auth"; | ||
export * from "./systems"; | ||
export * from "./textures"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum TexturesServiceType { | ||
TEXTURES_SERVICE_SKINS = "skins", | ||
TEXTURES_SERVICE_CLOAKS = "cloaks", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Breadcrumbs } from "./ui/Breadcrumbs"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ConnectTexturesDialog } from "./ui/ConnectTexturesDialog"; |
21 changes: 21 additions & 0 deletions
21
src/widgets/ConnectTexturesDialog/ui/ConnectTexturesDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ConnectTexturesForm } from "@/features/connect-textures-form"; | ||
|
||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/shared/ui/dialog"; | ||
|
||
interface GenerateLauncherDialogProps { | ||
open: boolean; | ||
onOpenChange: (open: boolean) => void; | ||
} | ||
|
||
export function ConnectTexturesDialog(props: GenerateLauncherDialogProps) { | ||
return ( | ||
<Dialog {...props}> | ||
<DialogContent className="sm:max-w-[800px]"> | ||
<DialogHeader> | ||
<DialogTitle>Подключение сервиса скинов и плащей</DialogTitle> | ||
</DialogHeader> | ||
<ConnectTexturesForm onOpenChange={props.onOpenChange} /> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |