Skip to content
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
10 changes: 10 additions & 0 deletions src/features/projects/remove/model/useRemoveProject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type DefaultError, useMutation, UseMutationOptions } from '@tanstack/react-query';
import { projectFabricKeys, ProjectHttp, type TProject } from 'entities/project';
import { useRouter, usePathname } from 'next/navigation';
import { routes } from 'shared/config';
import { toast } from 'sonner';

type RemoveProjectVariables = {
Expand All @@ -13,11 +15,19 @@ export type UseRemoveProjectOptions = Omit<
>;

export function useRemoveProject({ onSuccess, ...rest }: UseRemoveProjectOptions = {}) {
const router = useRouter();
const pathname = usePathname();

return useMutation<TProject.ActionResponse, DefaultError, RemoveProjectVariables>({
...rest,
mutationFn: ({ teamId, id }) => ProjectHttp.removeProject(teamId, id),
onSuccess: async (res, variables, _r, context) => {
onSuccess?.(res, variables, _r, context);

if (pathname !== routes.team.projects()) {
router.replace(routes.team.projects());
}

toast.success(res.message ?? 'Проект удалён');

await context.client.invalidateQueries({
Expand Down
6 changes: 5 additions & 1 deletion src/features/projects/remove/ui/RemoveProjectDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export function RemoveProjectDialog({ projectName, teamId, projectId, ...props }
/>
<AlertDialogFooter>
<AlertDialogCancel onClick={() => setInputValue('')}>Отмена</AlertDialogCancel>
<AlertDialogAction variant="destructive" disabled={!isMatch} onClick={onRemove}>
<AlertDialogAction
variant="destructive"
disabled={!isMatch || removeProject.isPending}
onClick={onRemove}
>
Удалить
</AlertDialogAction>
</AlertDialogFooter>
Expand Down
Loading