Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Обновление до версии 1 #112

Merged
merged 13 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/features/connect-textures-form/ui/ConnectTexturesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export function ConnectTexturesForm({
{
key: 'auroralauncher',
label: 'AuroraLauncher',
skinsUrl: 'https://api.aurora-launcher.ru/mojang/skin?username={userName}',
cloaksUrl: 'https://api.aurora-launcher.ru/mojang/cape?username={userName}',
skinsUrl: 'https://api.aurora-launcher.ru/mojang/username/skin/{userName}',
cloaksUrl: 'https://api.aurora-launcher.ru/mojang/username/cape/{userName}',
},
{
key: 'tlauncher',
Expand Down
11 changes: 7 additions & 4 deletions src/features/create-profile-form/ui/CreateProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ export function CreateProfileForm(props: CreateProfileFormProps) {
</FormItem>

<FormItem>
<FormLabel>Введите название сервера</FormLabel>
<FormLabel>Введите название профиля</FormLabel>
<FormControl>
<Input placeholder="Введите название сервера" {...form.register('name')} />
<Input placeholder="Введите название профиля" {...form.register('name')} />
</FormControl>
{form.formState.errors.name && (
<FormMessage>{form.formState.errors.name.message}</FormMessage>
)}
{/*<div className="text-gray-400 text-sm font-medium">*/}
{/* slug: {form.watch('name').toLowerCase().replace(/\s+/g, '-')}*/}
{/*</div>*/}
</FormItem>
<FormItem>
<FormLabel>Введите описание сервера</FormLabel>
<FormLabel>Введите описание профиля</FormLabel>
<FormControl>
<Textarea placeholder="Введите описание сервера" {...form.register('description')} />
<Textarea placeholder="Введите описание профиля" {...form.register('description')} />
</FormControl>
{form.formState.errors.description && (
<FormMessage>{form.formState.errors.description.message}</FormMessage>
Expand Down
4 changes: 4 additions & 0 deletions src/shared/api/contracts/user/UserRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ export type TGetPlayersResponse = ResponseBaseEntity & {
// Бан юзера
export type TPostBanPlayersRequest = string[];
export type TPostBanPlayersResponse = ResponseBaseEntity & {};

// Удаление юзера
export type TPostRemovePlayersRequest = string[];
export type TPostRemovePlayersResponse = ResponseBaseEntity & {};
4 changes: 4 additions & 0 deletions src/shared/enums/entity-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export enum EntityState {
ENTITY_STATE_ACTIVE = 2, // Профиль активен
ENTITY_STATE_INITIALIZE = 3, // Подготовка профиля
ENTITY_STATE_ERROR = 4, // Ошибка при работе с профилем
ENTITY_STATE_NEED_COMPILE = 5, // Необходима сборка профиля
ENTITY_STATE_PACKING = 6, // Необходима сборка профиля

ENTITY_STATE_DISABLED = 99999, // Профиль выключен
}
Expand All @@ -14,5 +16,7 @@ export enum EntityStateOption {
'OPTION_2' = 'Активен', // Профиль активен
'OPTION_3' = 'Подготовка', // Подготовка профиля
'OPTION_4' = 'Ошибка', // Ошибка при работе с профилем
'OPTION_5' = 'Необходима сборка', // Необходима сборка профиля
'OPTION_6' = 'Сборка', // Сборка профиля
'OPTION_99999' = 'Недоступен', // Профиль выключен
}
21 changes: 20 additions & 1 deletion src/shared/hooks/usePlayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { toast } from 'sonner';
import { playersService } from '@/shared/services/PlayersService';
import { modsKeys } from '@/shared/hooks/useMods';
import { isAxiosError } from '@/shared/lib/isAxiosError/isAxiosError';
import { TPostBanPlayersRequest } from '@/shared/api/contracts';
import { TPostBanPlayersRequest, TPostRemovePlayersRequest } from '@/shared/api/contracts';

export const playersKeys = {
all: ['players'] as const,
getPlayers: () => [...modsKeys.all, 'getPlayers'] as const,
banPlayer: () => [...modsKeys.all, 'banPlayer'] as const,
pardonPlayer: () => [...modsKeys.all, 'pardonPlayer'] as const,
removePlayer: () => [...modsKeys.all, 'pardonPlayer'] as const,
};

export const usePlayers = (search: string) => {
Expand Down Expand Up @@ -49,6 +50,24 @@ export const useBanPlayer = () => {
});
};

export const useRemoveUser = () => {
const queryClient = useQueryClient();

return useMutation({
mutationKey: playersKeys.banPlayer(),
mutationFn: (data: TPostRemovePlayersRequest) => playersService.removePlayer(data),
onSuccess: async (data) => {
await queryClient.invalidateQueries({ queryKey: playersKeys.all });
toast.success('Успешно', {
description: `Пользователь удален`,
});
},
onError: (error) => {
isAxiosError({ toast, error });
},
});
};

export const usePardonPlayer = () => {
const queryClient = useQueryClient();

Expand Down
14 changes: 13 additions & 1 deletion src/shared/hooks/useProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { toast } from 'sonner';
import { useRouter } from 'next/navigation';

import { useProfileCardStore } from '@/entities/ProfileCard/lib/store';
import {
ProfileBaseEntity,
TAddPlayerToProfileRequest,
Expand All @@ -25,8 +26,8 @@ import {
} from '@/shared/api/contracts';
import { profileService } from '@/shared/services/ProfileService';
import { isAxiosError } from '@/shared/lib/utils';
import { useProfileCardStore } from '@/entities/ProfileCard/lib/store';
import { modsKeys } from '@/shared/hooks/useMods';
import { EntityState } from '@/shared/enums';

export const profileKeys = {
all: ['profiles'] as const,
Expand Down Expand Up @@ -107,12 +108,14 @@ export const useCreateProfile = () => {

export const useLoadProfileMods = () => {
const queryClient = useQueryClient();
const { setState: setProfileCardState } = useProfileCardStore();

return useMutation({
mutationKey: profileKeys.addingMods(),
mutationFn: (data: TPostLoadProfileModRequest) => profileService.loadProfileMod(data),
onSuccess: async (data) => {
await queryClient.invalidateQueries({ queryKey: modsKeys.all });
setProfileCardState(EntityState.ENTITY_STATE_NEED_COMPILE);
toast.success('Успешно', {
description: 'Мод успешно загружен',
});
Expand All @@ -125,13 +128,15 @@ export const useLoadProfileMods = () => {

export const useLoadProfileModsByUrl = () => {
const queryClient = useQueryClient();
const { setState: setProfileCardState } = useProfileCardStore();

return useMutation({
mutationKey: profileKeys.addingModsByUrl(),
mutationFn: (data: TPostLoadProfileModByUrlRequest) =>
profileService.loadProfileModByLink(data),
onSuccess: async (data) => {
await queryClient.invalidateQueries({ queryKey: modsKeys.all });
setProfileCardState(EntityState.ENTITY_STATE_NEED_COMPILE);
toast.success('Успешно', {
description: 'Мод успешно загружен',
});
Expand All @@ -144,12 +149,14 @@ export const useLoadProfileModsByUrl = () => {

export const useRemoveProfileMod = () => {
const queryClient = useQueryClient();
const { setState: setProfileCardState } = useProfileCardStore();

return useMutation({
mutationKey: profileKeys.addingMods(),
mutationFn: (data: TRemoveProfileModRequest) => profileService.removeProfileMod(data),
onSuccess: async (data) => {
await queryClient.invalidateQueries({ queryKey: modsKeys.all });
setProfileCardState(EntityState.ENTITY_STATE_NEED_COMPILE);
toast.success('Успешно', {
description: 'Мод успешно удален',
});
Expand All @@ -161,9 +168,14 @@ export const useRemoveProfileMod = () => {
};

export const useEditProfile = () => {
const { setState: setProfileCardState } = useProfileCardStore();

return useMutation({
mutationKey: profileKeys.editing(),
mutationFn: (data: TPutProfileRequest) => profileService.editProfile(data),
onSuccess: (data) => {
setProfileCardState(EntityState.ENTITY_STATE_NEED_COMPILE);
},
onError: (error) => {
isAxiosError({ toast, error });
},
Expand Down
6 changes: 6 additions & 0 deletions src/shared/services/PlayersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class PlayersService {

return data;
}

async removePlayer(body: TPostBanPlayersRequest): Promise<TPostBanPlayersResponse> {
const { data } = await $api.post<TPostBanPlayersResponse>(`${this.BASE_URL}/remove`, body);

return data;
}
}

export const playersService = new PlayersService();
5 changes: 3 additions & 2 deletions src/widgets/client-hub/lib/useConnectionHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const useConnectionHub = (props: ConnectionHubProps) => {
})
.finally(() => {
setIsRestoring(false);
setProfileCardState(EntityState.ENTITY_STATE_LOADING);
setProfileCardState(EntityState.ENTITY_STATE_NEED_COMPILE);
});
};

Expand Down Expand Up @@ -185,7 +185,7 @@ export const useConnectionHub = (props: ConnectionHubProps) => {
const onBuildDistributive = () => {
setIsPacked(false);
setIsRestoring(true);
setProfileCardState(EntityState.ENTITY_STATE_ACTIVE);
setProfileCardState(EntityState.ENTITY_STATE_PACKING);
connectionHub
?.invoke('Build', profile?.profileName)
.then(() => {
Expand All @@ -202,6 +202,7 @@ export const useConnectionHub = (props: ConnectionHubProps) => {
}
})
.finally(() => {
setProfileCardState(EntityState.ENTITY_STATE_ACTIVE);
setIsRestoring(false);
});
};
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/client-hub/ui/ClientState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const stateColorMap: Record<EntityState, string> = {
[EntityState.ENTITY_STATE_DISABLED]: 'bg-red-500',
[EntityState.ENTITY_STATE_INITIALIZE]: 'bg-orange-500',
[EntityState.ENTITY_STATE_ERROR]: 'bg-red-500',
[EntityState.ENTITY_STATE_NEED_COMPILE]: 'bg-blue-500',
[EntityState.ENTITY_STATE_PACKING]: 'bg-orange-500',
};

export function ClientState({ state }: ClientStateProps) {
Expand Down
9 changes: 7 additions & 2 deletions src/widgets/game-mods/ui/GameMods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@ export const GameMods = ({ profile }: GameServersParams) => {
});
};

const canEditModsList = ![
EntityState.ENTITY_STATE_ACTIVE,
EntityState.ENTITY_STATE_NEED_COMPILE,
].includes(profile.state);

const removeMod = async (fileName: string) => {
await removeModMutate({ profileName: profile.profileName, modName: fileName });
};

return (
<div className="grid gap-y-4 relative">
{profile.state !== EntityState.ENTITY_STATE_ACTIVE && (
{canEditModsList && (
<div className="absolute w-full h-full z-[10] flex items-center justify-center">
<Card className="p-6 w-[50%]">
<CardHeader className="font-bold text-xl">Модификации недоступны</CardHeader>
Expand All @@ -71,7 +76,7 @@ export const GameMods = ({ profile }: GameServersParams) => {
)}
<div
className={clsx('flex flex-col md:flex-row gap-5', {
'blur-sm': profile.state !== EntityState.ENTITY_STATE_ACTIVE,
'blur-sm': canEditModsList,
})}
>
<div className="flex flex-col gap-3 w-full">
Expand Down
21 changes: 17 additions & 4 deletions src/widgets/players-table/lib/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import React from 'react';
import { createColumnHelper } from '@tanstack/table-core';
import { format } from 'date-fns';
import { GavelIcon } from 'lucide-react';
import { GavelIcon, UserXIcon } from 'lucide-react';

import { DataTableColumnHeader } from '@/entities/Table';
import { PlayerBaseEntity } from '@/shared/api/contracts';
import { $api } from '@/services/api.service';
import { Button } from '@/shared/ui/button';
import { useBanPlayer, usePardonPlayer } from '@/shared/hooks/usePlayers';
import { useBanPlayer, usePardonPlayer, useRemoveUser } from '@/shared/hooks/usePlayers';

enum ColumnHeader {
ICON = '',
Expand All @@ -25,11 +25,15 @@ enum ColumnHeader {
export const columnsHelper = createColumnHelper<PlayerBaseEntity>();
export const useColumns = () => {
const banPlayer = useBanPlayer();
const removePlayer = useRemoveUser();
const pardonPlayer = usePardonPlayer();

const banUser = async (data: string) => {
await banPlayer.mutateAsync([data]);
};
const removeUser = async (data: string) => {
await removePlayer.mutateAsync([data]);
};

const pardonUser = async (data: string) => {
await pardonPlayer.mutateAsync([data]);
Expand Down Expand Up @@ -99,7 +103,7 @@ export const useColumns = () => {
),
cell: ({ row }) => {
return (
<>
<div className="flex gap-2">
{row.original.isBanned ? (
<Button
variant="outline"
Expand All @@ -119,7 +123,16 @@ export const useColumns = () => {
Забанить
</Button>
)}
</>

<Button
variant="outline"
className="rounded-full h-8 gap-2"
onClick={() => removeUser(row.original.uuid)}
>
<UserXIcon size="12" />
Удалить
</Button>
</div>
);
},
}),
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/profiles-table/lib/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const useColumns = (props: UseColumnsProps) => {
cell: ({ getValue }) => getFormatDate(getValue()),
}),
columnsHelper.accessor('state', {
size: 50,
size: 270,
header: ({ column }) => (
<DataTableColumnHeader column={column} title={ColumnHeader.PROFILE_STATE} />
),
Expand Down