2023-01-12 08:19:13 +00:00
|
|
|
import { useApolloClient } from "@apollo/client";
|
2023-03-06 09:57:25 +00:00
|
|
|
import AppDeleteDialog from "@dashboard/apps/components/AppDeleteDialog";
|
|
|
|
import { appMessages } from "@dashboard/apps/messages";
|
|
|
|
import { EXTENSION_LIST_QUERY } from "@dashboard/apps/queries";
|
2023-01-16 09:45:12 +00:00
|
|
|
import NotFoundPage from "@dashboard/components/NotFoundPage";
|
2022-03-09 08:56:55 +00:00
|
|
|
import {
|
|
|
|
useAppActivateMutation,
|
|
|
|
useAppDeactivateMutation,
|
2023-01-12 08:19:13 +00:00
|
|
|
useAppDeleteMutation,
|
2023-08-08 10:25:10 +00:00
|
|
|
useAppQuery
|
2023-01-16 09:45:12 +00:00
|
|
|
} from "@dashboard/graphql";
|
|
|
|
import useNavigator from "@dashboard/hooks/useNavigator";
|
|
|
|
import useNotifier from "@dashboard/hooks/useNotifier";
|
|
|
|
import getAppErrorMessage from "@dashboard/utils/errors/app";
|
|
|
|
import createDialogActionHandlers from "@dashboard/utils/handlers/dialogActionHandlers";
|
2020-07-22 10:54:15 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
|
|
|
import AppActivateDialog from "../../components/AppActivateDialog";
|
|
|
|
import AppDeactivateDialog from "../../components/AppDeactivateDialog";
|
2023-06-29 13:50:13 +00:00
|
|
|
import { AppDetailsPage } from "../../components/AppDetailsPage";
|
2020-07-22 10:54:15 +00:00
|
|
|
import {
|
|
|
|
AppDetailsUrlDialog,
|
|
|
|
AppDetailsUrlQueryParams,
|
2023-03-01 14:04:53 +00:00
|
|
|
AppPaths,
|
|
|
|
AppUrls,
|
2020-07-22 10:54:15 +00:00
|
|
|
} from "../../urls";
|
2023-01-12 08:19:13 +00:00
|
|
|
import { messages } from "./messages";
|
2020-07-22 10:54:15 +00:00
|
|
|
|
2023-06-27 07:29:40 +00:00
|
|
|
interface Props {
|
2020-07-22 10:54:15 +00:00
|
|
|
id: string;
|
|
|
|
params: AppDetailsUrlQueryParams;
|
|
|
|
}
|
|
|
|
|
2023-06-27 07:29:40 +00:00
|
|
|
export const AppManageView: React.FC<Props> = ({ id, params }) => {
|
2023-01-12 08:19:13 +00:00
|
|
|
const client = useApolloClient();
|
2022-03-09 08:56:55 +00:00
|
|
|
const { data, loading, refetch } = useAppQuery({
|
2020-07-22 10:54:15 +00:00
|
|
|
displayLoader: true,
|
2022-06-21 09:36:55 +00:00
|
|
|
variables: { id },
|
2020-07-22 10:54:15 +00:00
|
|
|
});
|
2022-01-11 12:34:48 +00:00
|
|
|
|
|
|
|
const appExists = data?.app !== null;
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
const navigate = useNavigator();
|
|
|
|
const notify = useNotifier();
|
|
|
|
const intl = useIntl();
|
|
|
|
const mutationOpts = { variables: { id } };
|
|
|
|
const [activateApp, activateAppResult] = useAppActivateMutation({
|
|
|
|
onCompleted: data => {
|
|
|
|
const errors = data?.appActivate?.errors;
|
|
|
|
if (errors?.length === 0) {
|
|
|
|
notify({
|
|
|
|
status: "success",
|
2022-06-21 09:36:55 +00:00
|
|
|
text: intl.formatMessage(appMessages.appActivated),
|
2020-07-22 10:54:15 +00:00
|
|
|
});
|
|
|
|
refetch();
|
|
|
|
closeModal();
|
|
|
|
} else {
|
2022-12-29 12:51:54 +00:00
|
|
|
if (appExists && errors) {
|
2022-01-11 12:34:48 +00:00
|
|
|
errors.forEach(error =>
|
|
|
|
notify({
|
|
|
|
status: "error",
|
2022-06-21 09:36:55 +00:00
|
|
|
text: getAppErrorMessage(error, intl),
|
|
|
|
}),
|
2022-01-11 12:34:48 +00:00
|
|
|
);
|
|
|
|
}
|
2020-07-22 10:54:15 +00:00
|
|
|
}
|
2022-06-21 09:36:55 +00:00
|
|
|
},
|
2020-07-22 10:54:15 +00:00
|
|
|
});
|
|
|
|
const [deactivateApp, deactivateAppResult] = useAppDeactivateMutation({
|
|
|
|
onCompleted: data => {
|
|
|
|
const errors = data?.appDeactivate?.errors;
|
2022-12-29 12:51:54 +00:00
|
|
|
if (errors?.length === 0) {
|
2020-07-22 10:54:15 +00:00
|
|
|
notify({
|
|
|
|
status: "success",
|
2022-06-21 09:36:55 +00:00
|
|
|
text: intl.formatMessage(appMessages.appDeactivated),
|
2020-07-22 10:54:15 +00:00
|
|
|
});
|
|
|
|
refetch();
|
|
|
|
closeModal();
|
|
|
|
} else {
|
2022-12-29 12:51:54 +00:00
|
|
|
if (appExists && errors) {
|
2022-01-11 12:34:48 +00:00
|
|
|
errors.forEach(error =>
|
|
|
|
notify({
|
|
|
|
status: "error",
|
2022-06-21 09:36:55 +00:00
|
|
|
text: getAppErrorMessage(error, intl),
|
|
|
|
}),
|
2022-01-11 12:34:48 +00:00
|
|
|
);
|
|
|
|
}
|
2020-07-22 10:54:15 +00:00
|
|
|
}
|
2022-06-21 09:36:55 +00:00
|
|
|
},
|
2020-07-22 10:54:15 +00:00
|
|
|
});
|
|
|
|
|
2023-01-12 08:19:13 +00:00
|
|
|
const refetchExtensionList = () => {
|
|
|
|
client.refetchQueries({
|
|
|
|
include: [EXTENSION_LIST_QUERY],
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const removeAppNotify = () => {
|
|
|
|
notify({
|
|
|
|
status: "success",
|
|
|
|
text: intl.formatMessage(messages.appRemoved),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const [deleteApp, deleteAppOpts] = useAppDeleteMutation({
|
|
|
|
onCompleted: data => {
|
|
|
|
if (!data?.appDelete?.errors?.length) {
|
|
|
|
refetch();
|
|
|
|
refetchExtensionList();
|
|
|
|
removeAppNotify();
|
2023-03-01 14:04:53 +00:00
|
|
|
navigate(AppPaths.appListPath);
|
2023-01-12 08:19:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
const [openModal, closeModal] = createDialogActionHandlers<
|
|
|
|
AppDetailsUrlDialog,
|
|
|
|
AppDetailsUrlQueryParams
|
2023-03-01 14:04:53 +00:00
|
|
|
>(navigate, params => AppUrls.resolveAppDetailsUrl(id, params), params);
|
2020-07-22 10:54:15 +00:00
|
|
|
|
2023-01-12 08:19:13 +00:00
|
|
|
const handleActivateConfirm = () => activateApp(mutationOpts);
|
|
|
|
const handleDeactivateConfirm = () => deactivateApp(mutationOpts);
|
|
|
|
const handleRemoveConfirm = () => deleteApp(mutationOpts);
|
2020-07-22 10:54:15 +00:00
|
|
|
|
2022-01-11 12:34:48 +00:00
|
|
|
if (!appExists) {
|
2023-03-01 14:04:53 +00:00
|
|
|
return <NotFoundPage backHref={AppPaths.appListPath} />;
|
2022-01-11 12:34:48 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<AppActivateDialog
|
|
|
|
confirmButtonState={activateAppResult.status}
|
2022-12-29 12:51:54 +00:00
|
|
|
name={data?.app?.name || ""}
|
2020-07-22 10:54:15 +00:00
|
|
|
onClose={closeModal}
|
|
|
|
onConfirm={handleActivateConfirm}
|
|
|
|
open={params.action === "app-activate"}
|
|
|
|
/>
|
|
|
|
<AppDeactivateDialog
|
|
|
|
confirmButtonState={deactivateAppResult.status}
|
2022-12-29 12:51:54 +00:00
|
|
|
name={data?.app?.name || ""}
|
2020-07-22 10:54:15 +00:00
|
|
|
onClose={closeModal}
|
|
|
|
onConfirm={handleDeactivateConfirm}
|
|
|
|
open={params.action === "app-deactivate"}
|
|
|
|
/>
|
2023-01-12 08:19:13 +00:00
|
|
|
<AppDeleteDialog
|
|
|
|
confirmButtonState={deleteAppOpts.status}
|
|
|
|
name={data?.app?.name || ""}
|
|
|
|
onClose={closeModal}
|
|
|
|
onConfirm={handleRemoveConfirm}
|
|
|
|
type="EXTERNAL"
|
|
|
|
open={params.action === "app-delete"}
|
|
|
|
/>
|
2020-07-22 10:54:15 +00:00
|
|
|
<AppDetailsPage
|
2022-12-29 12:51:54 +00:00
|
|
|
data={data?.app || null}
|
2020-07-22 10:54:15 +00:00
|
|
|
loading={loading}
|
|
|
|
onAppActivateOpen={() => openModal("app-activate")}
|
|
|
|
onAppDeactivateOpen={() => openModal("app-deactivate")}
|
2023-01-12 08:19:13 +00:00
|
|
|
onAppDeleteOpen={() => openModal("app-delete")}
|
2020-07-22 10:54:15 +00:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|