@camunda/ccma-saas-frontend 0.8.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/components/c4-delete-account-modal/c4-delete-account-modal.d.ts +10 -0
- package/lib/esm/components/c4-delete-account-modal/c4-delete-account-modal.js +54 -0
- package/lib/esm/components/c4-delete-account-modal/c4-delete-account-modal.types.d.ts +47 -0
- package/lib/esm/components/c4-delete-account-modal/c4-delete-account-modal.types.js +33 -0
- package/lib/esm/externalUrls.const.d.ts +2 -0
- package/lib/esm/externalUrls.const.js +4 -0
- package/lib/esm/i18n/en/modals/users.json +8 -2
- package/lib/esm/index.d.ts +6 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/runtime/c4-console-authz.d.ts +13 -0
- package/lib/esm/runtime/c4-console-authz.js +17 -0
- package/lib/esm/widgets/user-account/c4-delete-account-widget.d.ts +5 -0
- package/lib/esm/widgets/user-account/c4-delete-account-widget.js +65 -0
- package/lib/esm/widgets/user-account/c4-delete-account-widget.types.d.ts +13 -0
- package/lib/esm/widgets/user-account/c4-delete-account-widget.types.js +6 -0
- package/lib/esm/widgets/user-account/use-delete-account-eligibility.d.ts +41 -0
- package/lib/esm/widgets/user-account/use-delete-account-eligibility.js +97 -0
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type JSX } from 'react';
|
|
2
|
+
import { type C4DeleteAccountModalProps } from './c4-delete-account-modal.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Look up a translation, and fall back to English when the host has no
|
|
5
|
+
* `t` function or no translation for `key`. Exported so the widget can use
|
|
6
|
+
* the same fallback for copy that does not live inside this component (the
|
|
7
|
+
* generic delete error).
|
|
8
|
+
*/
|
|
9
|
+
export declare function safeTranslate(t: ((key: string, options?: Record<string, unknown>) => string) | undefined, key: string, fallback: string, options?: Record<string, unknown>): string;
|
|
10
|
+
export declare const C4DeleteAccountModal: ({ t, open, isEnterpriseOwner, isEnterpriseAdmin, loading, onRequestClose, onRequestSubmit, preventCloseOnClickOutside, }: C4DeleteAccountModalProps) => JSX.Element;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
4
|
+
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
5
|
+
* You may not use this file except in compliance with the commercial license.
|
|
6
|
+
*/
|
|
7
|
+
import { useEffect, useState } from 'react';
|
|
8
|
+
import { C4_EXTERNAL_URLS } from '../../externalUrls.const.js';
|
|
9
|
+
import { Link, Modal, Stack, TextInput } from '../../ui/index.js';
|
|
10
|
+
import { useRadioFamily } from '../../ui/families.js';
|
|
11
|
+
import { C4AsyncModal } from '../c4-async-modal/c4-async-modal.js';
|
|
12
|
+
import { C4InlineNotification } from '../c4-inline-notification/c4-inline-notification.js';
|
|
13
|
+
import { C4_DELETE_ACCOUNT_REASONS, } from './c4-delete-account-modal.types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Look up a translation, and fall back to English when the host has no
|
|
16
|
+
* `t` function or no translation for `key`. Exported so the widget can use
|
|
17
|
+
* the same fallback for copy that does not live inside this component (the
|
|
18
|
+
* generic delete error).
|
|
19
|
+
*/
|
|
20
|
+
export function safeTranslate(t, key, fallback, options) {
|
|
21
|
+
try {
|
|
22
|
+
const translated = t?.(key, options);
|
|
23
|
+
if (!translated || translated === key) {
|
|
24
|
+
return fallback;
|
|
25
|
+
}
|
|
26
|
+
if (key.includes(':')) {
|
|
27
|
+
const withoutNamespace = key.split(':').slice(1).join(':');
|
|
28
|
+
if (translated === withoutNamespace) {
|
|
29
|
+
return fallback;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return translated;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return fallback;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export const C4DeleteAccountModal = ({ t, open, isEnterpriseOwner, isEnterpriseAdmin, loading, onRequestClose, onRequestSubmit, preventCloseOnClickOutside, }) => {
|
|
39
|
+
const { RadioButton, RadioButtonGroup } = useRadioFamily();
|
|
40
|
+
const [reason, setReason] = useState('');
|
|
41
|
+
const [explanation, setExplanation] = useState('');
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!open) {
|
|
44
|
+
setReason('');
|
|
45
|
+
setExplanation('');
|
|
46
|
+
}
|
|
47
|
+
}, [open]);
|
|
48
|
+
if (isEnterpriseOwner) {
|
|
49
|
+
return (_jsx(Modal, { modalHeading: safeTranslate(t, 'users:delete.headingSubscriptionOwner', 'Trying to delete this account?'), open: open, onRequestClose: onRequestClose, size: 'sm', passiveModal: true, id: 'c4-delete-account-modal', children: _jsx(Stack, { gap: 6, children: _jsxs("p", { children: [safeTranslate(t, 'users:delete.subscriptionOwner.intro', 'Since you are the owner for an organization with an active subscription, you should contact '), _jsx(Link, { inline: true, target: '_blank', href: C4_EXTERNAL_URLS.help.deleteAccountTechnicalSupport, children: "technical support" }), ' ', safeTranslate(t, 'users:delete.subscriptionOwner.middle', 'or our '), _jsx(Link, { inline: true, href: `mailto:${C4_EXTERNAL_URLS.help.deleteAccountCustomerSuccessEmail}`, children: "customer success" }), ' ', safeTranslate(t, 'users:delete.subscriptionOwner.outro', 'team to delete your account.')] }) }) }));
|
|
50
|
+
}
|
|
51
|
+
const explanationLabel = C4_DELETE_ACCOUNT_REASONS.find((candidate) => candidate.category === reason)
|
|
52
|
+
?.label ?? '';
|
|
53
|
+
return (_jsx(C4AsyncModal, { modalHeading: safeTranslate(t, 'users:delete.heading', 'Are you sure you want to delete this account?'), open: open, onRequestClose: onRequestClose, onRequestSubmit: () => onRequestSubmit({ reason, explanation }), primaryButtonText: safeTranslate(t, 'users:delete.finish.buttons.primary', 'Delete'), primaryButtonDisabled: loading || !reason, secondaryButtonText: safeTranslate(t, 'users:delete.finish.buttons.secondary', 'Cancel'), loadingText: safeTranslate(t, 'users:delete.loadingText', 'Deleting...'), danger: true, size: 'sm', preventCloseOnClickOutside: preventCloseOnClickOutside ?? true, children: _jsxs(Stack, { gap: 6, children: [isEnterpriseAdmin && (_jsx(C4InlineNotification, { kind: 'info', title: safeTranslate(t, 'users:delete.subscriptionAdmin.enterpriseTitle', 'Please note that deleting the account will not cancel your Enterprise subscription.'), subtitle: safeTranslate(t, 'users:delete.subscriptionAdmin.enterpriseSubtitle', "If you'd like to cancel your subscription, please contact customer-success@camunda.com.") })), _jsx("b", { children: safeTranslate(t, 'users:delete.finish.message', "We are sad to see you go. If we can't address your problem, we can at least improve our product for other users.") }), _jsx(RadioButtonGroup, { name: 'c4-delete-account-reason', valueSelected: reason, legendText: safeTranslate(t, 'users:delete.finish.reasonSelectionLabel', 'Why do you want to delete your account?'), orientation: 'vertical', onChange: (value) => setReason(value), children: C4_DELETE_ACCOUNT_REASONS.map((candidate) => (_jsx(RadioButton, { labelText: candidate.category, value: candidate.category }, candidate.category))) }), reason && (_jsx(TextInput, { id: 'c4-delete-account-explanation', labelText: explanationLabel, value: explanation, onChange: (event) => setExplanation(event.target.value) }))] }) }));
|
|
54
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { C4AsyncModalSubmitResponse } from '../c4-async-modal/c4-async-modal.types.js';
|
|
2
|
+
export interface C4DeleteAccountReason {
|
|
3
|
+
category: string;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The six reasons on the account-deletion form, and the follow-up question for
|
|
8
|
+
* each. Copied from console's `deleteAccountModel.ts`. A change to this list
|
|
9
|
+
* needs a separate ticket (see the Delete Account widget handoff plan).
|
|
10
|
+
*/
|
|
11
|
+
export declare const C4_DELETE_ACCOUNT_REASONS: C4DeleteAccountReason[];
|
|
12
|
+
export interface C4DeleteAccountModalProps {
|
|
13
|
+
t?: (key: string, options?: Record<string, unknown>) => string;
|
|
14
|
+
open: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* True for an enterprise-org owner. This variant shows a passive
|
|
17
|
+
* "contact support" message instead of the reason form: a self-service
|
|
18
|
+
* delete would leave the org without an owner.
|
|
19
|
+
*/
|
|
20
|
+
isEnterpriseOwner: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* True for an enterprise-org admin who is not an owner. The reason form
|
|
23
|
+
* still shows, with a reminder that the delete does not cancel the
|
|
24
|
+
* subscription of the org.
|
|
25
|
+
*/
|
|
26
|
+
isEnterpriseAdmin?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* True while the caller still resolves which variant applies. The submit
|
|
29
|
+
* button stays disabled, thus no delete can start before the gate settles
|
|
30
|
+
* and shows an enterprise owner the contact-support variant instead.
|
|
31
|
+
*/
|
|
32
|
+
loading?: boolean;
|
|
33
|
+
onRequestClose: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Called only for the reason-form variant, when the user picks a reason
|
|
36
|
+
* and submits. The owner variant has no submit action.
|
|
37
|
+
*/
|
|
38
|
+
onRequestSubmit: (params: {
|
|
39
|
+
reason: string;
|
|
40
|
+
explanation: string;
|
|
41
|
+
}) => Promise<C4AsyncModalSubmitResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* Defaults to `true`, like `C4DeleteOrganizationModal`: an outside click
|
|
44
|
+
* must not discard a reason the user already typed.
|
|
45
|
+
*/
|
|
46
|
+
preventCloseOnClickOutside?: boolean;
|
|
47
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
3
|
+
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
4
|
+
* You may not use this file except in compliance with the commercial license.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The six reasons on the account-deletion form, and the follow-up question for
|
|
8
|
+
* each. Copied from console's `deleteAccountModel.ts`. A change to this list
|
|
9
|
+
* needs a separate ticket (see the Delete Account widget handoff plan).
|
|
10
|
+
*/
|
|
11
|
+
export const C4_DELETE_ACCOUNT_REASONS = [
|
|
12
|
+
{
|
|
13
|
+
category: 'Technical issues',
|
|
14
|
+
label: 'What technical issues did you run into?',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
category: 'Too expensive',
|
|
18
|
+
label: 'What price would be more reasonable for you?',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
category: 'Switching to another product',
|
|
22
|
+
label: 'Which product are you switching to?',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
category: 'Not sure how to use the product',
|
|
26
|
+
label: 'Where did you get stuck?',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
category: 'Missing features I need',
|
|
30
|
+
label: 'What feature(s) would you like to see?',
|
|
31
|
+
},
|
|
32
|
+
{ category: 'Other', label: 'Please explain below' },
|
|
33
|
+
];
|
|
@@ -60,6 +60,8 @@ export declare const C4_EXTERNAL_URLS: {
|
|
|
60
60
|
readonly enterpriseSupport: "https://camunda.com/services/support/";
|
|
61
61
|
readonly talkToAnExpert: "https://camunda.com/platform/camunda-platform-enterprise-contact/?utm_medium=referral&utm_source=console&utm_campaign=ContactUs.CamundaPlatform.C8SaaS.Enterprise";
|
|
62
62
|
readonly requestCelpLicence: "https://camunda.com/educationee/";
|
|
63
|
+
readonly deleteAccountTechnicalSupport: "https://jira.camunda.com/";
|
|
64
|
+
readonly deleteAccountCustomerSuccessEmail: "customer-success@camunda.com";
|
|
63
65
|
};
|
|
64
66
|
};
|
|
65
67
|
export declare function getC4TalkToAnExpertUrl(properties?: {
|
|
@@ -60,6 +60,10 @@ export const C4_EXTERNAL_URLS = {
|
|
|
60
60
|
enterpriseSupport: 'https://camunda.com/services/support/',
|
|
61
61
|
talkToAnExpert: 'https://camunda.com/platform/camunda-platform-enterprise-contact/?utm_medium=referral&utm_source=console&utm_campaign=ContactUs.CamundaPlatform.C8SaaS.Enterprise',
|
|
62
62
|
requestCelpLicence: 'https://camunda.com/educationee/',
|
|
63
|
+
// Same links console's delete-account modal uses today for an enterprise
|
|
64
|
+
// owner, who must contact support instead of self-deleting.
|
|
65
|
+
deleteAccountTechnicalSupport: 'https://jira.camunda.com/',
|
|
66
|
+
deleteAccountCustomerSuccessEmail: 'customer-success@camunda.com',
|
|
63
67
|
},
|
|
64
68
|
};
|
|
65
69
|
export function getC4TalkToAnExpertUrl(properties) {
|
|
@@ -74,7 +74,9 @@
|
|
|
74
74
|
"heading": "Are you sure you want to delete this account?",
|
|
75
75
|
"headingSubscriptionOwner": "Trying to delete this account?",
|
|
76
76
|
"subscriptionOwner": {
|
|
77
|
-
"
|
|
77
|
+
"intro": "Since you are the owner for an organization with an active subscription, you should contact ",
|
|
78
|
+
"middle": "or our ",
|
|
79
|
+
"outro": "team to delete your account."
|
|
78
80
|
},
|
|
79
81
|
"subscriptionAdmin": {
|
|
80
82
|
"enterpriseTitle": "Please note that deleting the account will not cancel your Enterprise subscription.",
|
|
@@ -89,6 +91,10 @@
|
|
|
89
91
|
"secondary": "Cancel"
|
|
90
92
|
}
|
|
91
93
|
},
|
|
92
|
-
"loadingText": "Deleting..."
|
|
94
|
+
"loadingText": "Deleting...",
|
|
95
|
+
"error": {
|
|
96
|
+
"generic": "Couldn't delete your account. Try again.",
|
|
97
|
+
"subscriptionOwner": "You own an organization with an active subscription. Contact support to delete your account."
|
|
98
|
+
}
|
|
93
99
|
}
|
|
94
100
|
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -89,6 +89,8 @@ export { C4DashboardFirstLaunch } from './components/c4-dashboard-first-launch/c
|
|
|
89
89
|
export type { C4DashboardFirstLaunchProps } from './components/c4-dashboard-first-launch/c4-dashboard-first-launch.types.js';
|
|
90
90
|
export { C4DataTable } from './components/c4-data-table/c4-data-table.js';
|
|
91
91
|
export { C4DataTableSkeleton } from './components/c4-data-table/c4-data-table-skeleton.js';
|
|
92
|
+
export { C4DeleteAccountModal } from './components/c4-delete-account-modal/c4-delete-account-modal.js';
|
|
93
|
+
export type { C4DeleteAccountModalProps } from './components/c4-delete-account-modal/c4-delete-account-modal.types.js';
|
|
92
94
|
export { C4DeleteOrganizationModal } from './components/c4-delete-organization-modal/c4-delete-organization-modal.js';
|
|
93
95
|
export type { C4DeleteOrganizationModalProps } from './components/c4-delete-organization-modal/c4-delete-organization-modal.types.js';
|
|
94
96
|
export { C4Divider } from './components/c4-divider/c4-divider.js';
|
|
@@ -245,5 +247,9 @@ export { C4ManagementPage } from './widgets/management/c4-management-page.js';
|
|
|
245
247
|
export type { C4ManagementPageProps, C4ManagementTab, } from './widgets/management/c4-management-page.types.js';
|
|
246
248
|
export { MANAGEMENT_TABS, type ManagementTabDescriptor, type ManagementTabId, managementTab, } from './widgets/management/management-tabs.js';
|
|
247
249
|
export { useExtendTrial } from './widgets/use-extend-trial.js';
|
|
250
|
+
export { C4DeleteAccountWidget } from './widgets/user-account/c4-delete-account-widget.js';
|
|
251
|
+
export type { C4DeleteAccountWidgetProps } from './widgets/user-account/c4-delete-account-widget.types.js';
|
|
252
|
+
export type { DeleteAccountEligibility } from './widgets/user-account/use-delete-account-eligibility.js';
|
|
253
|
+
export { deriveDeleteAccountEligibility, useDeleteAccountEligibility, } from './widgets/user-account/use-delete-account-eligibility.js';
|
|
248
254
|
export { C4UserDetailsPage } from './widgets/user-details/c4-user-details-page.js';
|
|
249
255
|
export type { C4UserDetailsExternalLinks, C4UserDetailsNavigateEvent, C4UserDetailsPageProps, } from './widgets/user-details/c4-user-details-page.types.js';
|
package/lib/esm/index.js
CHANGED
|
@@ -48,6 +48,7 @@ export { C4CreateTrialOrganizationModal } from './components/c4-create-trial-org
|
|
|
48
48
|
export { C4DashboardFirstLaunch } from './components/c4-dashboard-first-launch/c4-dashboard-first-launch.js';
|
|
49
49
|
export { C4DataTable } from './components/c4-data-table/c4-data-table.js';
|
|
50
50
|
export { C4DataTableSkeleton } from './components/c4-data-table/c4-data-table-skeleton.js';
|
|
51
|
+
export { C4DeleteAccountModal } from './components/c4-delete-account-modal/c4-delete-account-modal.js';
|
|
51
52
|
export { C4DeleteOrganizationModal } from './components/c4-delete-organization-modal/c4-delete-organization-modal.js';
|
|
52
53
|
export { C4Divider } from './components/c4-divider/c4-divider.js';
|
|
53
54
|
export { C4EmptyState, } from './components/c4-empty-state/c4-empty-state.js';
|
|
@@ -138,4 +139,6 @@ export { C4ManagementApp } from './widgets/management/c4-management-app.js';
|
|
|
138
139
|
export { C4ManagementPage } from './widgets/management/c4-management-page.js';
|
|
139
140
|
export { MANAGEMENT_TABS, managementTab, } from './widgets/management/management-tabs.js';
|
|
140
141
|
export { useExtendTrial } from './widgets/use-extend-trial.js';
|
|
142
|
+
export { C4DeleteAccountWidget } from './widgets/user-account/c4-delete-account-widget.js';
|
|
143
|
+
export { deriveDeleteAccountEligibility, useDeleteAccountEligibility, } from './widgets/user-account/use-delete-account-eligibility.js';
|
|
141
144
|
export { C4UserDetailsPage } from './widgets/user-details/c4-user-details-page.js';
|
|
@@ -28,6 +28,19 @@ export interface DeriveConsoleAuthzParams {
|
|
|
28
28
|
accessToken: string;
|
|
29
29
|
orgId: string;
|
|
30
30
|
}
|
|
31
|
+
export interface OrgMembershipPermissions {
|
|
32
|
+
orgId: string;
|
|
33
|
+
roles: string[];
|
|
34
|
+
permissions?: OrganizationPermissions;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The org permissions of the user, for every org in the token, not just one.
|
|
38
|
+
*
|
|
39
|
+
* `useC4ConsoleAuthz` resolves one org (the current one). A widget that must
|
|
40
|
+
* check every org the user belongs to — the delete-account eligibility gate is
|
|
41
|
+
* the first case — needs this instead.
|
|
42
|
+
*/
|
|
43
|
+
export declare function deriveAllOrgMembershipPermissionsFromAccessToken(accessToken: string): OrgMembershipPermissions[];
|
|
31
44
|
export declare function deriveConsoleAuthzFromAccessToken(params: DeriveConsoleAuthzParams): Omit<C4ConsoleAuthzState, 'isLoading' | 'error'>;
|
|
32
45
|
/**
|
|
33
46
|
* Whether a developer-only org member is blocked from creating clusters by the
|
|
@@ -72,6 +72,23 @@ function inferOrgPermissionsFromRoles(roles) {
|
|
|
72
72
|
}
|
|
73
73
|
return { roles: normalizedRoles, permissions };
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* The org permissions of the user, for every org in the token, not just one.
|
|
77
|
+
*
|
|
78
|
+
* `useC4ConsoleAuthz` resolves one org (the current one). A widget that must
|
|
79
|
+
* check every org the user belongs to — the delete-account eligibility gate is
|
|
80
|
+
* the first case — needs this instead.
|
|
81
|
+
*/
|
|
82
|
+
export function deriveAllOrgMembershipPermissionsFromAccessToken(accessToken) {
|
|
83
|
+
const payload = tryDecodeJwtPayload(accessToken);
|
|
84
|
+
const orgsKey = `${AUTH0_BASE_CLAIM}/${AUTH0_TOKEN_ATTRIBUTE_ORGS}`;
|
|
85
|
+
const orgMemberships = orgMembershipsFromUnknown(payload?.[orgsKey]);
|
|
86
|
+
return orgMemberships.map((membership) => ({
|
|
87
|
+
orgId: membership.id,
|
|
88
|
+
roles: membership.roles,
|
|
89
|
+
permissions: inferOrgPermissionsFromRoles(membership.roles)?.permissions,
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
75
92
|
export function deriveConsoleAuthzFromAccessToken(params) {
|
|
76
93
|
const payload = tryDecodeJwtPayload(params.accessToken);
|
|
77
94
|
const tokenPermissions = stringArrayFromUnknown(payload?.permissions);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type JSX } from 'react';
|
|
2
|
+
import type { C4DeleteAccountWidgetProps } from './c4-delete-account-widget.types.js';
|
|
3
|
+
export declare const C4DeleteAccountWidget: (({ open, onRequestClose, onDeleted, }: C4DeleteAccountWidgetProps) => JSX.Element) & {
|
|
4
|
+
displayName: string;
|
|
5
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { UsersService } from '@camunda/ccma-api';
|
|
3
|
+
import { observer } from 'mobx-react-lite';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { C4DeleteAccountModal, safeTranslate, } from '../../components/c4-delete-account-modal/c4-delete-account-modal.js';
|
|
6
|
+
import { useC4ConsoleRuntime } from '../../runtime/c4-console-runtime-context.js';
|
|
7
|
+
import { toApiConfig } from '../../runtime/to-api-config.js';
|
|
8
|
+
import { useDeleteAccountEligibility } from './use-delete-account-eligibility.js';
|
|
9
|
+
/**
|
|
10
|
+
* Whether the request was refused with 403.
|
|
11
|
+
*
|
|
12
|
+
* The server holds the same enterprise-owner rule as the gate in this widget
|
|
13
|
+
* (#9934). A 403 thus means the gate let through what the server refuses:
|
|
14
|
+
* either the gate did not settle before the submit, or the two derivations
|
|
15
|
+
* drifted apart. For both, "try again" is the wrong advice — only support can
|
|
16
|
+
* delete that account.
|
|
17
|
+
*
|
|
18
|
+
* This reads `status` instead of `instanceof HttpError`, because a bundled
|
|
19
|
+
* host can hold its own copy of the class.
|
|
20
|
+
*/
|
|
21
|
+
function isForbidden(error) {
|
|
22
|
+
return error?.status === 403;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Self-service account deletion, as a standalone widget.
|
|
26
|
+
*
|
|
27
|
+
* A host passes only `open` / `onRequestClose` / `onDeleted`. The widget
|
|
28
|
+
* derives the enterprise-owner/admin gate and the translations from the c4
|
|
29
|
+
* runtime, and owns the delete request. The host still owns navigation: it
|
|
30
|
+
* must log the user out and pick a landing page after `onDeleted`, because
|
|
31
|
+
* that differs between Hub and console.
|
|
32
|
+
*
|
|
33
|
+
* Requires a `C4ConsoleRuntimeProvider` and a `C4ConsoleDataProvider` above it.
|
|
34
|
+
*/
|
|
35
|
+
const C4DeleteAccountWidgetImpl = ({ open, onRequestClose, onDeleted, }) => {
|
|
36
|
+
const runtime = useC4ConsoleRuntime();
|
|
37
|
+
const t = runtime.i18n?.t;
|
|
38
|
+
const apiConfig = useMemo(() => toApiConfig(runtime), [runtime]);
|
|
39
|
+
const eligibility = useDeleteAccountEligibility();
|
|
40
|
+
const handleSubmit = async (params) => {
|
|
41
|
+
try {
|
|
42
|
+
await UsersService.deleteMe({ config: apiConfig, params });
|
|
43
|
+
onDeleted();
|
|
44
|
+
return { success: true };
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
error: {
|
|
50
|
+
title: 'Error',
|
|
51
|
+
description: isForbidden(error)
|
|
52
|
+
? safeTranslate(t, 'users:delete.error.subscriptionOwner', 'You own an organization with an active subscription. Contact support to delete your account.')
|
|
53
|
+
: safeTranslate(t, 'users:delete.error.generic', "Couldn't delete your account. Try again."),
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return (_jsx(C4DeleteAccountModal, { t: t, open: open, isEnterpriseOwner: eligibility.isEnterpriseOwner, isEnterpriseAdmin: eligibility.isEnterpriseAdmin,
|
|
59
|
+
// Holds the submit until the gate settles: until then an enterprise
|
|
60
|
+
// owner would see the reason form, not the contact-support variant.
|
|
61
|
+
loading: eligibility.isLoading, onRequestClose: onRequestClose, onRequestSubmit: handleSubmit }));
|
|
62
|
+
};
|
|
63
|
+
// Reads console data (through `useDeleteAccountEligibility`) during render,
|
|
64
|
+
// so it must be an observer to re-render when that data changes.
|
|
65
|
+
export const C4DeleteAccountWidget = observer(C4DeleteAccountWidgetImpl);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface C4DeleteAccountWidgetProps {
|
|
2
|
+
/** The host owns this state, from its own navigation bar or menu. */
|
|
3
|
+
open: boolean;
|
|
4
|
+
onRequestClose: () => void;
|
|
5
|
+
/**
|
|
6
|
+
* Called after the account of the caller is gone.
|
|
7
|
+
*
|
|
8
|
+
* The widget does not log the user out and does not redirect. Hub and
|
|
9
|
+
* console send the user to different places after a delete, so the host
|
|
10
|
+
* must do both here.
|
|
11
|
+
*/
|
|
12
|
+
onDeleted: () => void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ExternalOrganizationDto } from '@camunda/ccma-shared-types';
|
|
2
|
+
export interface DeleteAccountEligibility {
|
|
3
|
+
/**
|
|
4
|
+
* The user owns an enterprise org. The widget must not offer self-service
|
|
5
|
+
* delete: it would leave the org without an owner.
|
|
6
|
+
*/
|
|
7
|
+
isEnterpriseOwner: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The user administers (but does not own) an enterprise org. Self-service
|
|
10
|
+
* delete is still allowed, with a reminder that it does not cancel the
|
|
11
|
+
* subscription of the org.
|
|
12
|
+
*/
|
|
13
|
+
isEnterpriseAdmin: boolean;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Set when the gate could not be derived, because the org list or the
|
|
17
|
+
* access token failed to load. Both flags are then false, thus the modal
|
|
18
|
+
* shows the reason form and the server stays the guard: `DELETE
|
|
19
|
+
* api/users/me` answers 403 for an enterprise owner (#9934).
|
|
20
|
+
*/
|
|
21
|
+
error?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The account-deletion gate, checked across every org the user belongs to.
|
|
25
|
+
*
|
|
26
|
+
* Console's own gate (`allOrgsPermissions()`) reads this from its internal org
|
|
27
|
+
* model. This hook derives the same result from data the c4 runtime already
|
|
28
|
+
* has: the sales plan of each org (`myOrgs`, the external-facing org list) and
|
|
29
|
+
* the org roles inside the access token. Both derive from the same roles
|
|
30
|
+
* today, but the source data differs, so pin the match with
|
|
31
|
+
* `use-delete-account-eligibility.spec.ts` rather than assume it holds.
|
|
32
|
+
*/
|
|
33
|
+
export declare function useDeleteAccountEligibility(): DeleteAccountEligibility;
|
|
34
|
+
/**
|
|
35
|
+
* Pure derivation, split out from the hook so the parity test can call it
|
|
36
|
+
* directly with fixed input instead of a mocked runtime.
|
|
37
|
+
*/
|
|
38
|
+
export declare function deriveDeleteAccountEligibility(params: {
|
|
39
|
+
accessToken: string;
|
|
40
|
+
myOrgs: ExternalOrganizationDto[];
|
|
41
|
+
}): DeleteAccountEligibility;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
3
|
+
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
4
|
+
* You may not use this file except in compliance with the commercial license.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
|
+
import { deriveAllOrgMembershipPermissionsFromAccessToken } from '../../runtime/c4-console-authz.js';
|
|
8
|
+
import { useC4ConsoleData } from '../../runtime/c4-console-data-context.js';
|
|
9
|
+
import { useC4ConsoleRuntime } from '../../runtime/c4-console-runtime-context.js';
|
|
10
|
+
const PENDING_ELIGIBILITY = {
|
|
11
|
+
isEnterpriseOwner: false,
|
|
12
|
+
isEnterpriseAdmin: false,
|
|
13
|
+
isLoading: true,
|
|
14
|
+
};
|
|
15
|
+
const UNKNOWN_ELIGIBILITY = {
|
|
16
|
+
isEnterpriseOwner: false,
|
|
17
|
+
isEnterpriseAdmin: false,
|
|
18
|
+
isLoading: false,
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The account-deletion gate, checked across every org the user belongs to.
|
|
22
|
+
*
|
|
23
|
+
* Console's own gate (`allOrgsPermissions()`) reads this from its internal org
|
|
24
|
+
* model. This hook derives the same result from data the c4 runtime already
|
|
25
|
+
* has: the sales plan of each org (`myOrgs`, the external-facing org list) and
|
|
26
|
+
* the org roles inside the access token. Both derive from the same roles
|
|
27
|
+
* today, but the source data differs, so pin the match with
|
|
28
|
+
* `use-delete-account-eligibility.spec.ts` rather than assume it holds.
|
|
29
|
+
*/
|
|
30
|
+
export function useDeleteAccountEligibility() {
|
|
31
|
+
const runtime = useC4ConsoleRuntime();
|
|
32
|
+
const data = useC4ConsoleData();
|
|
33
|
+
const [eligibility, setEligibility] = useState(PENDING_ELIGIBILITY);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
void data.fetchMyOrgs();
|
|
36
|
+
}, [data]);
|
|
37
|
+
const myOrgs = data.getMyOrgs();
|
|
38
|
+
// The org list says which orgs are enterprise, thus the gate needs it. When
|
|
39
|
+
// the fetch failed, settle instead of waiting for data that never arrives.
|
|
40
|
+
const myOrgsError = data.myOrgs.error;
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (myOrgsError) {
|
|
43
|
+
setEligibility({ ...UNKNOWN_ELIGIBILITY, error: myOrgsError });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!myOrgs) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const resolvedMyOrgs = myOrgs;
|
|
50
|
+
let isCancelled = false;
|
|
51
|
+
async function run() {
|
|
52
|
+
try {
|
|
53
|
+
const accessToken = await runtime.auth.getAccessToken();
|
|
54
|
+
if (isCancelled) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
setEligibility(deriveDeleteAccountEligibility({
|
|
58
|
+
accessToken,
|
|
59
|
+
myOrgs: resolvedMyOrgs,
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (isCancelled) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
setEligibility({ ...UNKNOWN_ELIGIBILITY, error });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
void run();
|
|
70
|
+
return () => {
|
|
71
|
+
isCancelled = true;
|
|
72
|
+
};
|
|
73
|
+
}, [myOrgs, myOrgsError, runtime.auth]);
|
|
74
|
+
return eligibility;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Pure derivation, split out from the hook so the parity test can call it
|
|
78
|
+
* directly with fixed input instead of a mocked runtime.
|
|
79
|
+
*/
|
|
80
|
+
export function deriveDeleteAccountEligibility(params) {
|
|
81
|
+
const memberships = deriveAllOrgMembershipPermissionsFromAccessToken(params.accessToken);
|
|
82
|
+
let isEnterpriseOwner = false;
|
|
83
|
+
let isEnterpriseAdmin = false;
|
|
84
|
+
for (const org of params.myOrgs) {
|
|
85
|
+
if (org.salesPlan?.type !== 'enterprise') {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const permissions = memberships.find((membership) => membership.orgId === org.uuid)?.permissions;
|
|
89
|
+
if (permissions?.org.users.admin.create) {
|
|
90
|
+
isEnterpriseOwner = true;
|
|
91
|
+
}
|
|
92
|
+
else if (permissions?.org.users.member.create) {
|
|
93
|
+
isEnterpriseAdmin = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { isEnterpriseOwner, isEnterpriseAdmin, isLoading: false };
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camunda/ccma-saas-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Camunda Composite Components",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/camunda/camunda-cloud-management-apps/issues"
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"react-markdown": "^8.0.7 || ^10.0.0"
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
|
-
"@camunda/ccma-api": "1.0.
|
|
99
|
+
"@camunda/ccma-api": "1.0.1",
|
|
100
100
|
"@camunda/ccma-shared-types": "1.0.0",
|
|
101
101
|
"@pactsafe/pactsafe-react-sdk": "2.15.0",
|
|
102
102
|
"cron-parser": "5.10.0",
|