Clean up selected checkbox on delete.

This commit is contained in:
Paulo Gustavo Veiga 2022-03-31 19:29:39 -03:00
parent 3c9fcbf8e1
commit e6e3bc2655
4 changed files with 30 additions and 24 deletions

View File

@ -16,7 +16,7 @@ const DeleteDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement
const [error, setError] = React.useState<ErrorInfo>(); const [error, setError] = React.useState<ErrorInfo>();
const mutation = useMutation((id: number) => client.deleteMap(id), { const mutation = useMutation((id: number) => client.deleteMap(id), {
onSuccess: () => handleOnMutationSuccess(onClose, queryClient), onSuccess: () => handleOnMutationSuccess(() => onClose(true), queryClient),
onError: (error: ErrorInfo) => { onError: (error: ErrorInfo) => {
setError(error); setError(error);
}, },

View File

@ -18,7 +18,7 @@ const DeleteMultiselectDialog = ({
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const mutation = useMutation((ids: number[]) => client.deleteMaps(ids), { const mutation = useMutation((ids: number[]) => client.deleteMaps(ids), {
onSuccess: () => handleOnMutationSuccess(onClose, queryClient), onSuccess: () => handleOnMutationSuccess(() => onClose(true), queryClient),
onError: (error) => { onError: (error) => {
console.error(`Unexpected error ${error}`); console.error(`Unexpected error ${error}`);
}, },

View File

@ -22,7 +22,7 @@ export type BasicMapInfo = {
type ActionDialogProps = { type ActionDialogProps = {
action?: ActionType; action?: ActionType;
mapsId: number[]; mapsId: number[];
onClose: () => void; onClose: (success?: boolean) => void;
fromEditor: boolean; fromEditor: boolean;
}; };
@ -78,12 +78,12 @@ export const handleOnMutationSuccess = (onClose: () => void, queryClient: QueryC
export type SimpleDialogProps = { export type SimpleDialogProps = {
mapId: number; mapId: number;
onClose: () => void; onClose: (success?: boolean) => void;
}; };
export type MultiDialogProps = { export type MultiDialogProps = {
mapsId: number[]; mapsId: number[];
onClose: () => void; onClose: (success?: boolean) => void;
}; };
export default ActionDispatcher; export default ActionDispatcher;

View File

@ -400,7 +400,6 @@ export const MapsList = (props: MapsListProps): React.ReactElement => {
actionType: 'delete', actionType: 'delete',
mapsId: selected, mapsId: selected,
}); });
setSelected([]);
}; };
const handleAddLabelClick = () => { const handleAddLabelClick = () => {
@ -699,7 +698,14 @@ export const MapsList = (props: MapsListProps): React.ReactElement => {
<ActionDispatcher <ActionDispatcher
action={activeDialog?.actionType} action={activeDialog?.actionType}
onClose={() => setActiveDialog(undefined)} onClose={(success) => {
setActiveDialog(undefined);
// If it was a success action, reset the selection list ...
if (success) {
setSelected([]);
}
}}
mapsId={activeDialog ? activeDialog.mapsId : []} mapsId={activeDialog ? activeDialog.mapsId : []}
/> />
</div> </div>