Skip to content

Commit 41d9104

Browse files
authored
fix: allow save security attribute when api key exists (#6048)
* allow save * move button * auto-save * fix margin
1 parent d7e5870 commit 41d9104

File tree

4 files changed

+27
-33
lines changed

4 files changed

+27
-33
lines changed

app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/components/ApiKeyButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const ApiKeyButton = ({
5151
<>
5252
<GenerateApiKeyButton
5353
loading={false}
54+
className="mr-2"
5455
theme={theme}
5556
disabled={Boolean(apiKeyId)}
5657
onClick={() => {

app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/components/ResponseDelivery.tsx

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,28 @@ export const ResponseDelivery = () => {
101101
const [purposeOption, setPurposeOption] = useState(formPurpose as PurposeOption);
102102

103103
/*--------------------------------------------*
104-
* Save Delivery Option
104+
* Save security attribute
105105
*--------------------------------------------*/
106-
const saveDeliveryOptions = useCallback(async () => {
107-
updateSecurityAttribute(classification);
108-
109-
const resultAttribute = (await updateTemplateSecurityAttribute({
110-
id,
111-
securityAttribute: classification,
112-
})) as FormServerError;
113-
114-
if (resultAttribute?.error) {
115-
toast.error(<ErrorSaving errorCode={FormServerErrorCodes.DELIVERY_OPTION} />, "wide");
116-
return;
117-
}
106+
const saveSecurityAttribute = useCallback(
107+
async (classification: ClassificationType) => {
108+
updateSecurityAttribute(classification);
109+
110+
const resultAttribute = (await updateTemplateSecurityAttribute({
111+
id,
112+
securityAttribute: classification,
113+
})) as FormServerError;
114+
115+
if (resultAttribute?.error) {
116+
toast.error(<ErrorSaving errorCode={FormServerErrorCodes.DELIVERY_OPTION} />, "wide");
117+
return;
118+
}
118119

119-
toast.success(t("settingsResponseDelivery.savedSuccessMessage"));
120+
toast.success(t("settingsResponseDelivery.savedSuccessMessage"));
120121

121-
refreshData && refreshData();
122-
}, [t, refreshData, id, classification, updateSecurityAttribute]);
122+
refreshData && refreshData();
123+
},
124+
[t, refreshData, id, updateSecurityAttribute]
125+
);
123126

124127
/*--------------------------------------------*
125128
* Save form purpose option
@@ -165,8 +168,9 @@ export const ResponseDelivery = () => {
165168
setDeliveryOptionValue(DeliveryOption.vault);
166169
}
167170
setClassification(value);
171+
saveSecurityAttribute(value);
168172
},
169-
[deliveryOptionValue]
173+
[deliveryOptionValue, saveSecurityAttribute]
170174
);
171175

172176
const handleDeleteApiKey = useCallback(() => {
@@ -200,11 +204,9 @@ export const ResponseDelivery = () => {
200204
lang={lang}
201205
isPublished={isPublished}
202206
classification={classification}
203-
disabled={hasApiKey}
204207
handleUpdateClassification={handleUpdateClassification}
205208
/>
206209
</div>
207-
208210
<div className="mb-10">
209211
<h2 className="mb-6">{t("settingsResponseDelivery.title")}</h2>
210212

@@ -296,19 +298,9 @@ export const ResponseDelivery = () => {
296298
<ApiDocNotes />
297299
</div>
298300
)}
299-
{deliveryOptionValue !== DeliveryOption.api && !hasApiKey && (
300-
<>
301-
<Button
302-
// disabled={!isValid || isPublished}
303-
disabled={isPublished}
304-
theme="secondary"
305-
onClick={saveDeliveryOptions}
306-
>
307-
{t("settingsResponseDelivery.saveButton")}
308-
</Button>
309-
<ResponseDeliveryHelpButtonWithApi />
310-
</>
311-
)}
301+
<div>
302+
<ResponseDeliveryHelpButtonWithApi />
303+
</div>
312304
</div>
313305

314306
{/*--------------------------------------------*

app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/components/dialogs/ResponseDeliveryHelpDialogApiWithApi.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const ResponseDeliveryHelpButtonWithApi = () => {
117117

118118
return (
119119
<>
120-
<InfoIcon className="ml-4 inline-block size-5" />
120+
<InfoIcon className="inline-block size-5" />
121121
<div className="ml-2 inline-block">
122122
<Button onClick={handleOpenDialog} theme="link">
123123
{t("settingsResponseDelivery.responseDeliveryHelpWithApi.cta")}

next-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference path="./.next/types/routes.d.ts" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

0 commit comments

Comments
 (0)