0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

fix(console): refresh hook on data updated (#3898)

This commit is contained in:
Xiao Yijun 2023-05-25 10:59:36 +08:00 committed by GitHub
parent e7ee0a9523
commit ab38cbffeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,7 +42,7 @@ function WebhookDetails() {
const { data, error, mutate } = useSWR<HookResponse, RequestError>(
id && buildUrl(`api/hooks/${id}`, { includeExecutionStats: String(true) })
);
const { executionStats } = data ?? {};
const { enabled: isEnabled, executionStats } = data ?? {};
const isLoading = !data && !error;
const api = useApi();
@ -53,7 +53,6 @@ function WebhookDetails() {
const [isDeleting, setIsDeleting] = useState(false);
const [isDisableFormOpen, setIsDisableFormOpen] = useState(false);
const [isUpdatingEnableState, setIsUpdatingEnableState] = useState(false);
const [isEnabled, setIsEnabled] = useState(data?.enabled ?? true);
useEffect(() => {
setIsDeleteFormOpen(false);
@ -84,11 +83,12 @@ function WebhookDetails() {
setIsUpdatingEnableState(true);
try {
const { enabled } = await api
const updatedHook = await api
.patch(`api/hooks/${data.id}`, { json: { enabled: !isEnabled } })
.json<Hook>();
setIsEnabled(enabled);
void mutate({ ...updatedHook, executionStats: data.executionStats });
setIsDisableFormOpen(false);
const { enabled } = updatedHook;
toast.success(
t(enabled ? 'webhook_details.webhook_reactivated' : 'webhook_details.webhook_disabled')
);