mirror of
https://github.com/suitenumerique/docs.git
synced 2026-09-22 17:45:12 +02:00
🔥(frontend) remove manual access deletion logic from move doc hook
Access and invitation cleanup on document move is now handled atomically by the backend. The frontend no longer needs to fetch and delete accesses/invitations after a successful move. Signed-off-by: Mohamed El Amine BOUKERFA <boukerfa.ma@gmail.com>
This commit is contained in:
@@ -2,12 +2,6 @@ import { TreeViewMoveModeEnum } from '@gouvfr-lasuite/ui-kit';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { APIError, errorCauses, fetchAPI } from '@/api';
|
||||
import {
|
||||
getDocAccesses,
|
||||
getDocInvitations,
|
||||
useDeleteDocAccess,
|
||||
useDeleteDocInvitation,
|
||||
} from '@/docs/doc-share';
|
||||
|
||||
import { KEY_LIST_DOC } from './useDocs';
|
||||
|
||||
@@ -37,46 +31,15 @@ export const moveDoc = async ({
|
||||
return response.json() as Promise<void>;
|
||||
};
|
||||
|
||||
export function useMoveDoc(deleteAccessOnMove = false) {
|
||||
export function useMoveDoc() {
|
||||
const queryClient = useQueryClient();
|
||||
const { mutate: handleDeleteInvitation } = useDeleteDocInvitation();
|
||||
const { mutate: handleDeleteAccess } = useDeleteDocAccess();
|
||||
|
||||
return useMutation<void, APIError, MoveDocParam>({
|
||||
mutationFn: moveDoc,
|
||||
async onSuccess(_data, variables, _onMutateResult, _context) {
|
||||
if (!deleteAccessOnMove) {
|
||||
return;
|
||||
}
|
||||
|
||||
onSuccess() {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: [KEY_LIST_DOC],
|
||||
});
|
||||
const accesses = await getDocAccesses({
|
||||
docId: variables.sourceDocumentId,
|
||||
});
|
||||
|
||||
const invitationsResponse = await getDocInvitations({
|
||||
docId: variables.sourceDocumentId,
|
||||
page: 1,
|
||||
});
|
||||
|
||||
const invitations = invitationsResponse.results;
|
||||
|
||||
await Promise.all([
|
||||
...invitations.map((invitation) =>
|
||||
handleDeleteInvitation({
|
||||
docId: variables.sourceDocumentId,
|
||||
invitationId: invitation.id,
|
||||
}),
|
||||
),
|
||||
...accesses.map((access) =>
|
||||
handleDeleteAccess({
|
||||
docId: variables.sourceDocumentId,
|
||||
accessId: access.id,
|
||||
}),
|
||||
),
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ type DocGridContentListProps = {
|
||||
export const DraggableDocGridContentList = ({
|
||||
docs,
|
||||
}: DocGridContentListProps) => {
|
||||
const { mutateAsync: handleMove, isError } = useMoveDoc(true);
|
||||
const { mutateAsync: handleMove, isError } = useMoveDoc();
|
||||
const modalConfirmation = useModal();
|
||||
const onDragData = useRef<DocDragEndData | null>(null);
|
||||
const { untitledDocument } = useTrans();
|
||||
|
||||
@@ -87,7 +87,7 @@ export const DocMoveModal = ({
|
||||
const docTargetTitle = docSelected?.title || untitledDocument;
|
||||
const modalConfirmation = useModal();
|
||||
const modalRequest = useModal();
|
||||
const { mutate: moveDoc } = useMoveDoc(true);
|
||||
const { mutate: moveDoc } = useMoveDoc();
|
||||
const [search, setSearch] = useState('');
|
||||
const { isDesktop, isTablet, isMobile } = useResponsiveStore();
|
||||
const isModal = (isDesktop || isTablet) && !isMobile;
|
||||
|
||||
Reference in New Issue
Block a user