Skip to content

Commit 84a998d

Browse files
added delete auth provider functionality
1 parent 1ea186d commit 84a998d

File tree

6 files changed

+60
-51
lines changed

6 files changed

+60
-51
lines changed

client/packages/lowcoder/src/api/idSourceApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class IdSourceApi extends Api {
4444
return Api.post(IdSourceApi.saveConfigURL, request);
4545
}
4646

47-
static deleteConfig(id: string): AxiosPromise<ApiResponse> {
48-
return Api.delete(IdSourceApi.deleteConfigURL(id));
47+
static deleteConfig(id: string, deleteConfig?: boolean): AxiosPromise<ApiResponse> {
48+
return Api.delete(IdSourceApi.deleteConfigURL(id), {delete: deleteConfig});
4949
}
5050

5151
static syncManual(authType: string): AxiosPromise<ApiResponse> {

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,12 +3545,12 @@ export const en = {
35453545
"formSelectPlaceholder": "Please Select the {label}",
35463546
"saveSuccess": "Saved Successfully",
35473547
"dangerLabel": "Danger Zone",
3548-
"dangerTip": "Disabling This ID Provider May Result in Some Users Being Unable to Log In. Proceed With Caution.",
3548+
"dangerTip": "Disabling or Deleting This ID Provider May Result in Some Users Being Unable to Log In. Proceed With Caution.",
35493549
"disable": "Disable",
35503550
"disableSuccess": "Disabled Successfully",
35513551
"encryptedServer": "-------- Encrypted on the Server Side --------",
35523552
"disableTip": "Tips",
3553-
"disableContent": "Disabling This ID Provider May Result in Some Users Being Unable to Log In. Are You Sure to Proceed?",
3553+
"disableContent": "{action} This ID Provider May Result in Some Users Being Unable to Log In. Are You Sure to Proceed?",
35543554
"manualTip": "",
35553555
"lockTip": "The Content is Locked. To Make Changes, Please Click the {icon} to Unlock.",
35563556
"lockModalContent": "Changing the 'ID Attribute' Field Can Have Significant Impacts on User Identification. Please Confirm That You Understand the Implications of This Change Before Proceeding.",

client/packages/lowcoder/src/pages/setting/idSource/detail/deleteConfig.tsx

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,62 @@ import { trans } from "i18n";
44
import { useState } from "react";
55
import { validateResponse } from "api/apiUtils";
66
import IdSourceApi from "api/idSourceApi";
7-
import { DangerIcon, CustomModal } from "lowcoder-design";
7+
import { CustomModal } from "lowcoder-design";
88
import history from "util/history";
99
import { OAUTH_PROVIDER_SETTING } from "constants/routesURL";
1010
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
11+
import Flex from "antd/es/flex";
12+
import Alert from "antd/es/alert";
1113

12-
export const DeleteConfig = (props: { id: string }) => {
14+
export const DeleteConfig = (props: {
15+
id: string,
16+
allowDelete?: boolean,
17+
allowDisable?: boolean,
18+
}) => {
19+
const [disableLoading, setDisableLoading] = useState(false);
1320
const [deleteLoading, setDeleteLoading] = useState(false);
14-
const handleDelete = () => {
21+
22+
const handleDelete = (deleteConfig?: boolean) => {
23+
const setLoading = deleteConfig ? setDeleteLoading : setDisableLoading;
24+
const action = deleteConfig ? trans("delete") : trans("idSource.disable");
1525
CustomModal.confirm({
1626
title: trans("idSource.disableTip"),
17-
content: trans("idSource.disableContent"),
27+
content: trans("idSource.disableContent", {action}),
1828
onConfirm: () => {
19-
setDeleteLoading(true);
20-
IdSourceApi.deleteConfig(props.id)
21-
.then((resp) => {
22-
if (validateResponse(resp)) {
23-
messageInstance.success(trans("idSource.disableSuccess"), 0.8, () =>
29+
setLoading(true);
30+
IdSourceApi.deleteConfig(props.id, deleteConfig)
31+
.then((resp) => {
32+
if (validateResponse(resp)) {
33+
const successMsg = deleteConfig ? trans("home.deleteSuccessMsg") : trans("idSource.disableSuccess");
34+
messageInstance.success(successMsg, 0.8, () =>
2435
history.push(OAUTH_PROVIDER_SETTING)
2536
);
2637
}
2738
})
2839
.catch((e) => messageInstance.error(e.message))
29-
.finally(() => setDeleteLoading(false));
40+
.finally(() => setLoading(false));
3041
},
3142
});
3243
};
3344
return (
3445
<DeleteWrapper>
35-
<div>{trans("idSource.dangerLabel")}</div>
36-
<div className="danger-tip">
37-
<DangerIcon />
38-
{trans("idSource.dangerTip")}
39-
</div>
40-
<Button loading={deleteLoading} onClick={() => handleDelete()}>
41-
{trans("idSource.disable")}
42-
</Button>
46+
<h4>{trans("idSource.dangerLabel")}</h4>
47+
<Alert
48+
className="danger-tip"
49+
description={trans("idSource.dangerTip")}
50+
type="warning"
51+
showIcon
52+
/>
53+
<Flex gap={8}>
54+
<Button danger disabled={props.allowDisable} loading={disableLoading} onClick={() => handleDelete()}>
55+
{trans("idSource.disable")}
56+
</Button>
57+
{props.allowDelete && (
58+
<Button type="primary" danger disabled={props.allowDisable} loading={deleteLoading} onClick={() => handleDelete(true)}>
59+
{trans("delete")}
60+
</Button>
61+
)}
62+
</Flex>
4363
</DeleteWrapper>
4464
);
4565
};

client/packages/lowcoder/src/pages/setting/idSource/detail/index.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,22 @@ import { sourceMappingKeys } from "../OAuthForms/GenericOAuthForm";
4444
import Flex from "antd/es/flex";
4545

4646
type IdSourceDetailProps = {
47-
location: Location & { state: ConfigItem };
47+
location: Location & { state: { config: ConfigItem, totalEnabledConfigs: number }};
4848
};
4949

5050
export const IdSourceDetail = (props: IdSourceDetailProps) => {
51-
const configDetail = props.location.state;
51+
const {
52+
config: configDetail,
53+
totalEnabledConfigs,
54+
} = props.location.state;
5255
const [form] = useForm();
5356
const [lock, setLock] = useState(() => {
54-
const config = props.location.state;
57+
const { config } = props.location.state;
5558
return !config.ifLocal;
5659
});
5760
const [saveLoading, setSaveLoading] = useState(false);
5861
const [saveDisable, setSaveDisable] = useState(() => {
59-
const config = props.location.state;
62+
const { config } = props.location.state;
6063
if (
6164
(config.authType === AuthType.Form && !config.enable) ||
6265
(!config.ifLocal && !config.enable)
@@ -324,7 +327,11 @@ export const IdSourceDetail = (props: IdSourceDetailProps) => {
324327
{configDetail.enable && (
325328
<>
326329
<Divider />
327-
<DeleteConfig id={configDetail.id} />
330+
<DeleteConfig
331+
id={configDetail.id}
332+
allowDelete={configDetail.authType !== AuthType.Form}
333+
allowDisable={!Boolean(totalEnabledConfigs)}
334+
/>
328335
</>
329336
)}
330337
</Content>

client/packages/lowcoder/src/pages/setting/idSource/list.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { FreeTypes } from "pages/setting/idSource/idSourceConstants";
3333
import { messageInstance, AddIcon } from "lowcoder-design";
3434
import { currentOrgAdmin } from "../../../util/permissionUtils";
3535
import CreateModal from "./createModal";
36-
import _ from "lodash";
3736
import { HelpText } from "components/HelpText";
3837
import { IconControlView } from "@lowcoder-ee/comps/controls/iconControl";
3938

@@ -42,6 +41,7 @@ export const IdSourceList = (props: any) => {
4241
const config = useSelector(selectSystemConfig);
4342
const { currentOrgId} = user;
4443
const [configs, setConfigs] = useState<ConfigItem[]>([]);
44+
const [enabledConfigs, setEnabledConfigs] = useState<ConfigItem[]>([]);
4545
const [fetching, setFetching] = useState(false);
4646
const [modalVisible, setModalVisible] = useState(false);
4747
const enableEnterpriseLogin = useSelector(selectSystemConfig)?.featureFlag?.enableEnterpriseLogin;
@@ -76,8 +76,8 @@ export const IdSourceList = (props: any) => {
7676
let res: ConfigItem[] = resp.data.data.filter((item: ConfigItem) =>
7777
IdSource.includes(item.authType)
7878
);
79-
// res = _.uniqBy(res, 'authType');
8079
setConfigs(res);
80+
setEnabledConfigs(res.filter(item => item.enable));
8181
}
8282
})
8383
.catch((e) => {
@@ -126,7 +126,7 @@ export const IdSourceList = (props: any) => {
126126
}
127127
history.push({
128128
pathname: OAUTH_PROVIDER_DETAIL,
129-
state: record,
129+
state: { config: record, totalEnabledConfigs: enabledConfigs.length },
130130
});
131131
},
132132
})}

client/packages/lowcoder/src/pages/setting/idSource/styledComponents.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,9 @@ export const DeleteWrapper = styled.div`
258258
line-height: 19px;
259259
260260
.danger-tip {
261-
height: 32px;
262-
padding: 0 16px 0 8px;
263-
margin: 5px 0 8px 0;
264-
background: #fff3f1;
261+
max-width: 440px;
262+
padding: 8px 16px;
263+
margin: 5px 0 12px 0;
265264
border-radius: 4px;
266265
display: inline-flex;
267266
align-items: center;
@@ -270,23 +269,6 @@ export const DeleteWrapper = styled.div`
270269
margin-right: 8px;
271270
}
272271
}
273-
274-
.ant-btn {
275-
min-width: 84px;
276-
display: block;
277-
padding: 4px 8px;
278-
background: #fef4f4;
279-
border: 1px solid #fccdcd;
280-
font-size: 13px;
281-
color: #f73131;
282-
283-
&:hover,
284-
&.ant-btn-loading {
285-
background: #feecec;
286-
}
287-
288-
${btnLoadingCss}
289-
}
290272
`;
291273

292274
export const StatusSpan = styled.span`

0 commit comments

Comments
 (0)