2023-05-03 13:51:02 +00:00
|
|
|
import type ScopeRepresentation from "@keycloak/keycloak-admin-client/lib/defs/scopeRepresentation";
|
2022-01-04 09:17:43 +00:00
|
|
|
import { Alert, AlertVariant } from "@patternfly/react-core";
|
2023-05-03 13:51:02 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-01-04 09:17:43 +00:00
|
|
|
|
2023-05-03 13:51:02 +00:00
|
|
|
import { adminClient } from "../../admin-client";
|
2022-01-04 09:17:43 +00:00
|
|
|
import { useAlerts } from "../../components/alert/Alerts";
|
|
|
|
import { ConfirmDialogModal } from "../../components/confirm-dialog/ConfirmDialog";
|
2023-05-03 13:51:02 +00:00
|
|
|
import type { PermissionScopeRepresentation } from "./Scopes";
|
2022-01-04 09:17:43 +00:00
|
|
|
|
|
|
|
type DeleteScopeDialogProps = {
|
|
|
|
clientId: string;
|
|
|
|
selectedScope:
|
2023-01-13 12:07:13 +00:00
|
|
|
| PermissionScopeRepresentation
|
2022-01-04 09:17:43 +00:00
|
|
|
| ScopeRepresentation
|
|
|
|
| undefined;
|
|
|
|
refresh: () => void;
|
|
|
|
open: boolean;
|
|
|
|
toggleDialog: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const DeleteScopeDialog = ({
|
|
|
|
clientId,
|
|
|
|
selectedScope,
|
|
|
|
refresh,
|
|
|
|
open,
|
|
|
|
toggleDialog,
|
|
|
|
}: DeleteScopeDialogProps) => {
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2022-01-04 09:17:43 +00:00
|
|
|
const { addAlert, addError } = useAlerts();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConfirmDialogModal
|
|
|
|
open={open}
|
|
|
|
toggleDialog={toggleDialog}
|
|
|
|
titleKey="clients:deleteScope"
|
|
|
|
continueButtonLabel="clients:confirm"
|
|
|
|
onConfirm={async () => {
|
|
|
|
try {
|
|
|
|
await adminClient.clients.delAuthorizationScope({
|
|
|
|
id: clientId,
|
|
|
|
scopeId: selectedScope?.id!,
|
|
|
|
});
|
|
|
|
addAlert(t("resourceScopeSuccess"), AlertVariant.success);
|
|
|
|
refresh();
|
|
|
|
} catch (error) {
|
|
|
|
addError("clients:resourceScopeError", error);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t("deleteScopeConfirm")}
|
|
|
|
{selectedScope &&
|
|
|
|
"permissions" in selectedScope &&
|
|
|
|
selectedScope.permissions &&
|
|
|
|
selectedScope.permissions.length > 0 && (
|
|
|
|
<Alert
|
|
|
|
variant="warning"
|
|
|
|
isInline
|
|
|
|
isPlain
|
|
|
|
title={t("deleteScopeWarning")}
|
|
|
|
className="pf-u-pt-lg"
|
|
|
|
>
|
|
|
|
<p className="pf-u-pt-xs">
|
|
|
|
{selectedScope.permissions.map((permission) => (
|
|
|
|
<strong key={permission.id} className="pf-u-pr-md">
|
|
|
|
{permission.name}
|
|
|
|
</strong>
|
|
|
|
))}
|
|
|
|
</p>
|
|
|
|
</Alert>
|
|
|
|
)}
|
|
|
|
</ConfirmDialogModal>
|
|
|
|
);
|
|
|
|
};
|