-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Arsenii1109/GL-44
Adding UnicoreCMS
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 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 { AuthenticationFormUniCoreCMS } from "@/features/authentication-unicorecms-form/ui/AuthenticationFormUniCoreCMS"; |
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,11 @@ | ||
import { z } from "zod"; | ||
|
||
export const integrationSchema = z.object({ | ||
authType: z.number(), | ||
endpoint: z | ||
.string() | ||
.min(1, { message: "Вы не заполнили поле" }) | ||
.transform((v) => v.trim()), | ||
}); | ||
|
||
export type IntegrationFormSchemaType = z.infer<typeof integrationSchema>; |
80 changes: 80 additions & 0 deletions
80
src/features/authentication-unicorecms-form/ui/AuthenticationFormUniCoreCMS.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,80 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
|
||
import { SubmitHandler, useForm } from "react-hook-form"; | ||
|
||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
|
||
import { useEditIntegration, useGetActiveAuthIntegrations } from "@/shared/hooks"; | ||
import { cn } from "@/shared/lib/utils"; | ||
import { Button } from "@/shared/ui/button"; | ||
import { Form, FormControl, FormItem, FormLabel, FormMessage } from "@/shared/ui/form"; | ||
import { Icons } from "@/shared/ui/icons"; | ||
import { Input } from "@/shared/ui/input"; | ||
import { AuthenticationType } from "@/shared/enums"; | ||
|
||
import { IntegrationFormSchemaType, integrationSchema } from "../lib/static"; | ||
|
||
interface SignInFormProps extends React.HTMLAttributes<HTMLDivElement> { | ||
onOpenChange: (open: boolean) => void; | ||
} | ||
|
||
export function AuthenticationFormUniCoreCMS({ | ||
className, | ||
onOpenChange, | ||
...props | ||
}: SignInFormProps) { | ||
const { data: integration } = useGetActiveAuthIntegrations(); | ||
|
||
const { mutateAsync, isPending } = useEditIntegration(); | ||
|
||
const form = useForm<IntegrationFormSchemaType>({ | ||
values: { | ||
endpoint: | ||
integration.authType === AuthenticationType.AUTHENTICATION_TYPE_UNICORECMS | ||
? String(integration.endpoint) | ||
: "", | ||
authType: | ||
integration.authType === AuthenticationType.AUTHENTICATION_TYPE_UNICORECMS | ||
? integration.authType | ||
: AuthenticationType.AUTHENTICATION_TYPE_UNICORECMS, | ||
}, | ||
resolver: zodResolver(integrationSchema), | ||
}); | ||
|
||
const onSubmit: SubmitHandler<IntegrationFormSchemaType> = async ( | ||
data: IntegrationFormSchemaType, | ||
) => { | ||
await mutateAsync(data).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)}> | ||
<FormItem> | ||
<FormLabel>Введите ссылку на Ваш Backend</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Введите ссылку на Ваш Backend" {...form.register("endpoint")} /> | ||
</FormControl> | ||
{form.formState.errors.endpoint && ( | ||
<FormMessage>{form.formState.errors.endpoint.message}</FormMessage> | ||
)} | ||
</FormItem> | ||
|
||
<Button | ||
type="submit" | ||
className="w-fit ml-auto" | ||
disabled={isPending || !form.formState.isDirty} | ||
> | ||
{isPending && <Icons.spinner className="mr-2 h-4 w-4 animate-spin" />} | ||
Сохранить | ||
</Button> | ||
</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