Skip to content

Commit 0c55e39

Browse files
authored
Use swagger api for Add IDP Configuration (#3201)
1 parent b544395 commit 0c55e39

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

api/embedded_spec.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,6 +3299,8 @@ paths:
32993299
post:
33003300
summary: Create IDP Configuration
33013301
operationId: CreateConfiguration
3302+
consumes:
3303+
- application/json
33023304
parameters:
33033305
- name: type
33043306
description: IDP Configuration Type

web-app/src/api/consoleApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,6 +5091,7 @@ export class Api<
50915091
method: "POST",
50925092
body: body,
50935093
secure: true,
5094+
type: ContentType.Json,
50945095
format: "json",
50955096
...params,
50965097
}),

web-app/src/screens/Console/IDP/AddIDPConfiguration.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ import {
2626
Switch,
2727
} from "mds";
2828
import { useNavigate } from "react-router-dom";
29-
import { ErrorResponseHandler } from "../../../common/types";
3029
import { useAppDispatch } from "../../../store";
3130
import { modalStyleUtils } from "../Common/FormComponents/common/styleLibrary";
3231
import {
3332
setErrorSnackMessage,
3433
setHelpName,
3534
setServerNeedsRestart,
3635
} from "../../../systemSlice";
37-
import useApi from "../Common/Hooks/useApi";
3836
import PageHeaderWrapper from "../Common/PageHeaderWrapper/PageHeaderWrapper";
3937
import HelpMenu from "../HelpMenu";
38+
import { api } from "api";
39+
import { ApiError, HttpResponse, SetIDPResponse } from "api/consoleApi";
40+
import { errorToHandler } from "api/errors";
4041

4142
type AddIDPConfigurationProps = {
4243
classes?: any;
@@ -46,7 +47,6 @@ type AddIDPConfigurationProps = {
4647
title: string;
4748
backLink: string;
4849
formFields: object;
49-
endpoint: string;
5050
};
5151

5252
const AddIDPConfiguration = ({
@@ -56,7 +56,6 @@ const AddIDPConfiguration = ({
5656
backLink,
5757
title,
5858
formFields,
59-
endpoint,
6059
}: AddIDPConfigurationProps) => {
6160
const extraFormFields = {
6261
name: {
@@ -76,16 +75,7 @@ const AddIDPConfiguration = ({
7675
const dispatch = useAppDispatch();
7776

7877
const [fields, setFields] = useState<any>({});
79-
80-
const onSuccess = (res: any) => {
81-
navigate(backLink);
82-
dispatch(setServerNeedsRestart(res.restart === true));
83-
};
84-
85-
const onError = (err: ErrorResponseHandler) =>
86-
dispatch(setErrorSnackMessage(err));
87-
88-
const [loading, invokeApi] = useApi(onSuccess, onError);
78+
const [loadingCreate, setLoadingCreate] = useState<boolean>(false);
8979

9080
const validSave = () => {
9181
for (const [key, value] of Object.entries(extraFormFields)) {
@@ -108,6 +98,7 @@ const AddIDPConfiguration = ({
10898
};
10999

110100
const addRecord = (event: React.FormEvent) => {
101+
setLoadingCreate(true);
111102
event.preventDefault();
112103
const name = fields["name"];
113104
let input = "";
@@ -116,7 +107,17 @@ const AddIDPConfiguration = ({
116107
input += `${key}=${fields[key]} `;
117108
}
118109
}
119-
invokeApi("POST", endpoint, { name, input });
110+
111+
api.idp
112+
.createConfiguration("openid", { name, input })
113+
.then((res: HttpResponse<SetIDPResponse, ApiError>) => {
114+
navigate(backLink);
115+
dispatch(setServerNeedsRestart(res.data.restart === true));
116+
})
117+
.catch(async (res: HttpResponse<SetIDPResponse, ApiError>) => {
118+
dispatch(setErrorSnackMessage(errorToHandler(res.error)));
119+
})
120+
.finally(() => setLoadingCreate(false));
120121
};
121122

122123
const renderFormField = (key: string, value: any) => {
@@ -197,7 +198,7 @@ const AddIDPConfiguration = ({
197198
type="submit"
198199
variant="callAction"
199200
color="primary"
200-
disabled={loading || !validSave()}
201+
disabled={loadingCreate || !validSave()}
201202
label={"Save"}
202203
/>
203204
</Grid>

web-app/src/screens/Console/IDP/AddIDPOpenIDConfiguration.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const AddIDPOpenIDConfiguration = () => {
3838
header={"OpenID Configurations"}
3939
backLink={IAM_PAGES.IDP_OPENID_CONFIGURATIONS}
4040
title={"Create OpenID Configuration"}
41-
endpoint={"/api/v1/idp/openid/"}
4241
formFields={openIDFormFields}
4342
/>
4443
);

0 commit comments

Comments
 (0)