mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
fix: api key delete bug (#1524)
This commit is contained in:
@@ -41,87 +41,92 @@ export const useConfirm = (props?: {
|
|||||||
|
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
|
|
||||||
const confirmCb = useRef<any>();
|
const confirmCb = useRef<Function>();
|
||||||
const cancelCb = useRef<any>();
|
const cancelCb = useRef<any>();
|
||||||
|
|
||||||
return {
|
const openConfirm = (
|
||||||
openConfirm: useCallback(
|
confirm?: Function,
|
||||||
(confirm?: any, cancel?: any, customContent?: string | React.ReactNode) => {
|
cancel?: any,
|
||||||
confirmCb.current = confirm;
|
customContent?: string | React.ReactNode
|
||||||
cancelCb.current = cancel;
|
) => {
|
||||||
|
confirmCb.current = confirm;
|
||||||
|
cancelCb.current = cancel;
|
||||||
|
|
||||||
customContent && setCustomContent(customContent);
|
customContent && setCustomContent(customContent);
|
||||||
|
|
||||||
return onOpen;
|
return onOpen;
|
||||||
},
|
};
|
||||||
[onOpen]
|
|
||||||
),
|
|
||||||
onClose,
|
|
||||||
ConfirmModal: useCallback(
|
|
||||||
({
|
|
||||||
closeText = t('common.Cancel'),
|
|
||||||
confirmText = t('common.Confirm'),
|
|
||||||
isLoading,
|
|
||||||
bg,
|
|
||||||
countDown = 0
|
|
||||||
}: {
|
|
||||||
closeText?: string;
|
|
||||||
confirmText?: string;
|
|
||||||
isLoading?: boolean;
|
|
||||||
bg?: string;
|
|
||||||
countDown?: number;
|
|
||||||
}) => {
|
|
||||||
const timer = useRef<any>();
|
|
||||||
const [countDownAmount, setCountDownAmount] = useState(countDown);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const ConfirmModal = useCallback(
|
||||||
timer.current = setInterval(() => {
|
({
|
||||||
setCountDownAmount((val) => {
|
closeText = t('common.Cancel'),
|
||||||
if (val <= 0) {
|
confirmText = t('common.Confirm'),
|
||||||
clearInterval(timer.current);
|
isLoading,
|
||||||
}
|
bg,
|
||||||
return val - 1;
|
countDown = 0
|
||||||
});
|
}: {
|
||||||
}, 1000);
|
closeText?: string;
|
||||||
}, []);
|
confirmText?: string;
|
||||||
|
isLoading?: boolean;
|
||||||
|
bg?: string;
|
||||||
|
countDown?: number;
|
||||||
|
}) => {
|
||||||
|
const timer = useRef<any>();
|
||||||
|
const [countDownAmount, setCountDownAmount] = useState(countDown);
|
||||||
|
|
||||||
return (
|
useEffect(() => {
|
||||||
<MyModal isOpen={isOpen} iconSrc={iconSrc} title={title} maxW={['90vw', '500px']}>
|
timer.current = setInterval(() => {
|
||||||
<ModalBody pt={5} whiteSpace={'pre-wrap'}>
|
setCountDownAmount((val) => {
|
||||||
{customContent}
|
if (val <= 0) {
|
||||||
</ModalBody>
|
clearInterval(timer.current);
|
||||||
{!hideFooter && (
|
}
|
||||||
<ModalFooter>
|
return val - 1;
|
||||||
{showCancel && (
|
});
|
||||||
<Button
|
}, 1000);
|
||||||
variant={'whiteBase'}
|
}, []);
|
||||||
onClick={() => {
|
|
||||||
onClose();
|
|
||||||
typeof cancelCb.current === 'function' && cancelCb.current();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{closeText}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MyModal isOpen={isOpen} iconSrc={iconSrc} title={title} maxW={['90vw', '500px']}>
|
||||||
|
<ModalBody pt={5} whiteSpace={'pre-wrap'}>
|
||||||
|
{customContent}
|
||||||
|
</ModalBody>
|
||||||
|
{!hideFooter && (
|
||||||
|
<ModalFooter>
|
||||||
|
{showCancel && (
|
||||||
<Button
|
<Button
|
||||||
bg={bg ? bg : map.bg}
|
variant={'whiteBase'}
|
||||||
isDisabled={countDownAmount > 0}
|
|
||||||
ml={4}
|
|
||||||
isLoading={isLoading}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onClose();
|
onClose();
|
||||||
typeof confirmCb.current === 'function' && confirmCb.current();
|
typeof cancelCb.current === 'function' && cancelCb.current();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{countDownAmount > 0 ? `${countDownAmount}s` : confirmText}
|
{closeText}
|
||||||
</Button>
|
</Button>
|
||||||
</ModalFooter>
|
)}
|
||||||
)}
|
|
||||||
</MyModal>
|
<Button
|
||||||
);
|
bg={bg ? bg : map.bg}
|
||||||
},
|
isDisabled={countDownAmount > 0}
|
||||||
[customContent, hideFooter, iconSrc, isOpen, map.bg, onClose, showCancel, t, title]
|
ml={4}
|
||||||
)
|
isLoading={isLoading}
|
||||||
|
onClick={() => {
|
||||||
|
onClose();
|
||||||
|
typeof confirmCb.current === 'function' && confirmCb.current();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{countDownAmount > 0 ? `${countDownAmount}s` : confirmText}
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
)}
|
||||||
|
</MyModal>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[customContent, hideFooter, iconSrc, isOpen, map.bg, onClose, showCancel, t, title]
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
openConfirm,
|
||||||
|
onClose,
|
||||||
|
ConfirmModal
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -68,7 +68,9 @@ const ApiKeyTable = ({ tips, appId }: { tips: string; appId?: string }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { mutate: onclickRemove, isLoading: isDeleting } = useMutation({
|
const { mutate: onclickRemove, isLoading: isDeleting } = useMutation({
|
||||||
mutationFn: async (id: string) => delOpenApiById(id),
|
mutationFn: async (id: string) => {
|
||||||
|
return delOpenApiById(id);
|
||||||
|
},
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
refetch();
|
refetch();
|
||||||
}
|
}
|
||||||
@@ -212,7 +214,7 @@ const ApiKeyTable = ({ tips, appId }: { tips: string; appId?: string }) => {
|
|||||||
label: t('common.Delete'),
|
label: t('common.Delete'),
|
||||||
icon: 'delete',
|
icon: 'delete',
|
||||||
type: 'danger',
|
type: 'danger',
|
||||||
onClick: openConfirm(() => onclickRemove(_id))
|
onClick: () => openConfirm(() => onclickRemove(_id))()
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
Reference in New Issue
Block a user