Skip to content

Commit

Permalink
refactoring tosts (#93)
Browse files Browse the repository at this point in the history
Co-authored-by: vterentev <vaterentev@icloud.com>
  • Loading branch information
Scondic and vterentev authored Nov 10, 2024
1 parent 3d0062a commit 8a0262b
Show file tree
Hide file tree
Showing 32 changed files with 288 additions and 595 deletions.
56 changes: 0 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@radix-ui/react-toast": "^1.2.1",
"@radix-ui/react-tooltip": "^1.1.2",
"@tanstack/react-query": "^5.50.1",
"@tanstack/react-query-devtools": "^5.50.1",
Expand Down
6 changes: 2 additions & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Manrope } from "next/font/google";
import { config } from "@/core/configs";
import { QueryProvider, ThemeProvider, TooltipProvider } from "@/core/providers";
import { cn } from "@/shared/lib/utils";
import { Toaster } from "@/shared/ui/toaster";
import { Toaster as Sonner } from "@/shared/ui/sonner";
import { Toaster } from "@/shared/ui/sonner";

import "./globals.css";

Expand Down Expand Up @@ -36,8 +35,7 @@ export default function RootLayout({
>
<TooltipProvider>{children}</TooltipProvider>
</ThemeProvider>
<Toaster />
<Sonner position="top-right" />
<Toaster position="top-right" />
</QueryProvider>
</body>
</html>
Expand Down
7 changes: 2 additions & 5 deletions src/features/build-client-form/lib/hooks/useOnSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { SubmitHandler } from "react-hook-form";
import { toast } from "sonner";

import { ClientBuildFormSchemaType } from "../static";

import { useConnectionHub } from "@/widgets/generate-launcher-dialog";
import { toast } from "@/shared/ui/use-toast";


interface UseOnSubmitBuildParams {
connectionHub: ReturnType<typeof useConnectionHub>["connectionHub"];
Expand All @@ -20,9 +19,7 @@ export const useOnSubmit = ({ connectionHub, state, version }: UseOnSubmitBuildP
state.setIsBuilding(() => true);
connectionHub?.invoke("Compile", version, data.operatingSystem).then(() => {});
} catch (error: unknown) {
toast({
variant: "destructive",
title: "Ошибка!",
toast.error("Ошибка", {
description: JSON.stringify(error),
});
} finally {
Expand Down
7 changes: 2 additions & 5 deletions src/features/download-client-form/lib/hooks/useOnSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { SubmitHandler } from "react-hook-form";
import { toast } from "sonner";

import { ClientDownloadFormSchemaType } from "../static";

import { useConnectionHub } from "@/widgets/generate-launcher-dialog";
import { toast } from "@/shared/ui/use-toast";


interface UseOnSubmitParams {
connectionHub: ReturnType<typeof useConnectionHub>["connectionHub"];
Expand All @@ -19,9 +18,7 @@ export const useOnSubmit = ({ connectionHub, state }: UseOnSubmitParams) => {
state.setIsDownload(() => true);
connectionHub?.invoke("Download", data.branch, data.host, data.folder).then(() => {});
} catch (error: unknown) {
toast({
variant: "destructive",
title: "Ошибка!",
toast.error("Ошибка", {
description: JSON.stringify(error),
});
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import { DatabaseIcon, ImagesIcon, UsersIcon } from "lucide-react";

import { EditSettingsPlatformSchema, EditSettingsPlatformSchemaType } from "../lib/zod";

import { StorageType, StorageTypeOption } from "@/shared/enums";
import {
StorageType,
StorageTypeOption,
TextureProtocol,
TextureProtocolOption,
} from "@/shared/enums";
import { useEditSettingsPlatform, useSettingsPlatform } from "@/shared/hooks";
import { Form, FormControl, FormField, FormItem, FormMessage } from "@/shared/ui/form";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/shared/ui/select";
import { Button } from "@/shared/ui/button";
import { Icons } from "@/shared/ui/icons";
import { Switch } from "@/shared/ui/switch";
import { Input } from "@/shared/ui/input";
import { TextureProtocol, TextureProtocolOption } from "@/shared/enums/textureProtocol";
import { enumValues } from "@/shared/lib/utils";

export const EditSettingsPlatformForm = () => {
Expand Down
26 changes: 22 additions & 4 deletions src/features/update-client-form/ui/UpdateClientForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { ClientUpdateFormSchemaType, ClientUpdateSchema } from "../lib/static";

import { Icons } from "@/shared/ui/icons";
import { useLauncherBuildVersions, useLauncherUpload } from "@/shared/hooks";
import {
useLauncherActualVersion,
useLauncherBuildVersions,
useLauncherUpload,
} 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 {
Form,
FormControl,
FormDescription,
FormItem,
FormLabel,
FormMessage,
} from "@/shared/ui/form";
import { Textarea } from "@/shared/ui/textarea";
import { Input } from "@/shared/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/shared/ui/select";


interface UpdateClientFormProps extends React.HTMLAttributes<HTMLDivElement> {
onOpenChange: () => void;
}

export function UpdateClientForm({ className, onOpenChange, ...props }: UpdateClientFormProps) {
const { data: versions } = useLauncherBuildVersions();
const { data: actualVersion } = useLauncherActualVersion();

const { mutateAsync, isPending } = useLauncherUpload();

Expand Down Expand Up @@ -78,11 +89,18 @@ export function UpdateClientForm({ className, onOpenChange, ...props }: UpdateCl
<FormItem className="flex-1">
<FormLabel>Введите версию обновления</FormLabel>
<FormControl>
<Input placeholder="1.0.0" {...field} />
<Input placeholder="1.0.0.0" {...field} />
</FormControl>
{form.formState.errors.version && (
<FormMessage>{form.formState.errors.version.message}</FormMessage>
)}
<FormDescription className="flex flex-col gap-1">
{actualVersion?.map(([title, kek]) => (
<span key={title}>
Актуальная версия для {title}: {kek.version}
</span>
))}
</FormDescription>
</FormItem>
)}
/>
Expand Down
7 changes: 7 additions & 0 deletions src/shared/api/contracts/integrations/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AuthIntegrationBaseEntity,
BranchBaseEntity,
DiscordBaseEntity,
LauncherActualVersionBaseEntity,
LauncherBuildsBaseEntity,
SentryBaseEntity,
TextureServiceBaseEntity,
Expand Down Expand Up @@ -39,6 +40,12 @@ export type TGetLauncherBuildVersionsResponse = ResponseBaseEntity & {
data: LauncherBuildsBaseEntity[];
};

// Получение актуальной версии лаунчера
export type TGetLauncherActualVersionRequest = {};
export type TGetLauncherActualVersionResponse = ResponseBaseEntity & {
data: LauncherActualVersionBaseEntity;
};

// Обновление лаунчера
export type TPostLauncherUploadRequest = FormData;
export type TPostLauncherUploadResponse = ResponseBaseEntity & {};
Expand Down
10 changes: 10 additions & 0 deletions src/shared/api/contracts/integrations/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export type LauncherBuildsBaseEntity = {
dateTime: string;
};

export type LauncherActualVersionBaseEntity = Record<
string,
{
version: string;
title: string;
description: string;
guid: string;
}
>;

export type SentryBaseEntity = {
url: string;
};
Expand Down
2 changes: 1 addition & 1 deletion src/shared/api/contracts/notification/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NotificationStatus } from "@/shared/enums/notificationType";
import { NotificationStatus } from "@/shared/enums";

export type NotificationBaseEntity = {
message: string;
Expand Down
3 changes: 1 addition & 2 deletions src/shared/api/contracts/settings/platform/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { StorageType } from "@/shared/enums/storages";
import { TextureProtocol } from "@/shared/enums/textureProtocol";
import { StorageType, TextureProtocol } from "@/shared/enums";

export type SettingsPlatformBaseEntity = {
registrationIsEnabled: boolean;
Expand Down
18 changes: 18 additions & 0 deletions src/shared/enums/entity-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export enum EntityState {
ENTITY_STATE_CREATED = 0, // Профиль создан
ENTITY_STATE_LOADING = 1, // Профиль загружается
ENTITY_STATE_ACTIVE = 2, // Профиль активен
ENTITY_STATE_INITIALIZE = 3, // Подготовка профиля
ENTITY_STATE_ERROR = 4, // Ошибка при работе с профилем

ENTITY_STATE_DISABLED = 99999, // Профиль выключен
}

export enum EntityStateOption {
"OPTION_0" = "Создан", // Профиль создан
"OPTION_1" = "Загружается", // Профиль загружается
"OPTION_2" = "Активен", // Профиль активен
"OPTION_3" = "Подготовка", // Подготовка профиля
"OPTION_4" = "Ошибка", // Ошибка при работе с профилем
"OPTION_99999" = "Недоступен", // Профиль выключен
}
13 changes: 0 additions & 13 deletions src/shared/enums/entityState.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/shared/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export * from "./analytics-interval";
export * from "./auth";
export * from "./entityState";
export * from "./entity-state";
export * from "./integration";
export * from "./notificationType";
export * from "./notification-type";
export * from "./project-type";
export * from "./storages";
export * from "./systems";
export * from "./texture-protocol";
export * from "./textures";
File renamed without changes.
File renamed without changes.
41 changes: 15 additions & 26 deletions src/shared/hooks/useAuthorization.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,53 @@
import { useRouter } from "next/navigation";
import { useMutation } from "@tanstack/react-query";
import { isAxiosError } from "axios";
import { toast } from "sonner";

import { TPostSignInRequest, TPostSignUpRequest } from "@/shared/api/contracts";
import { DASHBOARD_PAGES } from "@/shared/routes";
import { authService } from "@/shared/services";
import { useToast } from "@/shared/ui/use-toast";
import { isAxiosError } from "@/shared/lib/isAxiosError/isAxiosError";

export const useRegistration = () => {
const route = useRouter();
const { toast } = useToast();

return useMutation({
mutationKey: ["signup"],
mutationFn: (data: TPostSignUpRequest) => authService.signUp(data),
onSuccess: () => {
toast({
title: "Успешная регистрация",
toast.success("Успешная регистрация", {
description: "Добро пожаловать в платформу",
});

route.push(DASHBOARD_PAGES.PROFILES);
},
onError: (error) => {
if (isAxiosError(error)) {
toast({
variant: "destructive",
title: (error.response && error.response.data.message) || "Ошибка!",
description:
(error.response && error.response.data.errors?.[0]) ||
"Ошибка сервиса авторизации. Обратитесь к администратору платформы",
});
}
isAxiosError({
toast,
error,
customDescription: "Ошибка сервиса авторизации. Обратитесь к администратору платформы",
});
},
});
};

export const useLogin = () => {
const route = useRouter();
const { toast } = useToast();

return useMutation({
mutationKey: ["signin"],
mutationFn: (data: TPostSignInRequest) => authService.signIn(data),
onSuccess: () => {
toast({
title: "Успешная авторизация",
toast.success("Успешная авторизация", {
description: "Добро пожаловать в платформу",
});
route.push(DASHBOARD_PAGES.PROFILES);
},
onError: (error) => {
if (isAxiosError(error)) {
toast({
variant: "destructive",
title: (error.response && error.response.data.message) || "Ошибка!",
description:
(error.response && error.response.data.errors?.[0]) ||
"Ошибка сервиса авторизации. Обратитесь к администратору платформы",
});
}
isAxiosError({
toast,
error,
customDescription: "Ошибка сервиса авторизации. Обратитесь к администратору платформы",
});
},
});
};
Loading

0 comments on commit 8a0262b

Please sign in to comment.