Skip to content

Commit

Permalink
Bugfix/fix create profile (#86)
Browse files Browse the repository at this point in the history
* Fix create profile

* Delecte console log

---------

Co-authored-by: vterentev <[email protected]>
  • Loading branch information
Scondic and vterentev authored Oct 24, 2024
1 parent 5062751 commit c9821df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
27 changes: 16 additions & 11 deletions src/features/create-profile-form/ui/CreateProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ export function CreateProfileForm(props: CreateProfileFormProps) {
minecraftVersion: form.watch("version"),
},
{
enabled:
form.watch("gameLoader") === GameLoaderOption.FORGE.toString() ||
form.watch("gameLoader") === GameLoaderOption.LITELOADER.toString() ||
form.watch("gameLoader") === GameLoaderOption.FABRIC.toString() ||
form.watch("gameLoader") === GameLoaderOption.NEOFORGE.toString(),
enabled: form.watch("gameLoader") !== GameLoaderOption.VANILLA.toString(),
},
);

Expand Down Expand Up @@ -193,10 +189,7 @@ export function CreateProfileForm(props: CreateProfileFormProps) {
)}
/>

{(form.watch("gameLoader") === GameLoaderOption.FORGE.toString() ||
form.watch("gameLoader") === GameLoaderOption.NEOFORGE.toString() ||
form.watch("gameLoader") === GameLoaderOption.FABRIC.toString() ||
form.watch("gameLoader") === GameLoaderOption.LITELOADER.toString()) && (
{form.watch("gameLoader") !== GameLoaderOption.VANILLA.toString() && (
<Controller
name="loaderVersion"
render={({ field }) => (
Expand All @@ -205,7 +198,11 @@ export function CreateProfileForm(props: CreateProfileFormProps) {
<FormCombobox
name={field.name}
value={field.value}
placeholder="Выберите версию загрузчика"
placeholder={
loaderVersion.data?.length
? "Выберите версию загрузчика"
: "Данная версия игры не поддерживается загрузчиком"
}
placeholderInputSearch="Поиск версии загрузчика"
options={loaderVersion && loaderVersion.data}
description="Данная версия игры не поддерживается загрузчиком"
Expand All @@ -222,7 +219,15 @@ export function CreateProfileForm(props: CreateProfileFormProps) {
)}

<div className="flex justify-end">
<Button disabled={isPending || !form.formState.isDirty || loaderVersion.isError}>
<Button
disabled={
isPending ||
!form.formState.isDirty ||
loaderVersion.isError ||
versions.isFetching ||
loaderVersion.isFetching
}
>
{isPending && <Icons.spinner className="mr-2 h-4 w-4 animate-spin" />}
Создать
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/shared/hooks/useProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const useGetGameVersions = (
>,
): UseQueryResult<TGameVersionsResponse["data"]> => {
return useQuery({
queryKey: profileKeys.gameVersions(body.minecraftVersion),
queryKey: [profileKeys.gameVersions(body.minecraftVersion), { gameLoader: body.gameLoader }],
queryFn: async () => await profileService.getGameVersions(body),
select: (data) => data.data.data,
...options,
Expand Down
8 changes: 4 additions & 4 deletions src/shared/ui/FormCombobox/ui/FormCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type FormComboboxParams = {
};

// TODO: Добавить Disabled: boolean
// TODO: Провести рефакторинг и отказаться от Textera
// TODO: Провести рефакторинг и отказаться от Textarea

export const FormCombobox = ({
value,
Expand All @@ -39,8 +39,8 @@ export const FormCombobox = ({
setValue,
description,
}: FormComboboxParams) => {
if (isLoading) return <Textera text="Загрузка" />;
if (isError && description) return <Textera text={description} />;
if (isLoading) return <Textarea text="Загрузка" />;
if (isError && description) return <Textarea text={description} />;

return (
<>
Expand Down Expand Up @@ -84,7 +84,7 @@ export const FormCombobox = ({
);
};

const Textera = ({ text }: { text: string }) => {
const Textarea = ({ text }: { text: string }) => {
return (
<div className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1">
<span className="text-muted-foreground">{text}</span>
Expand Down

0 comments on commit c9821df

Please sign in to comment.