Skip to content

Commit d99f7fd

Browse files
RachelElysiagetvictor
authored andcommitted
Fleet UI: Calendar settings iterations (#17779)
1 parent 7d90439 commit d99f7fd

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

frontend/pages/admin/IntegrationsPage/cards/Calendars/Calendars.tsx

+30-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const API_KEY_JSON_PLACEHOLDER = `{
3333
"type": "service_account",
3434
"project_id": "fleet-in-your-calendar",
3535
"private_key_id": "<private key id>",
36-
"private_key": "-----BEGIN PRIVATE KEY-----\n<private key>\n-----END PRIVATE KEY-----\n",
36+
"private_key": "-----BEGIN PRIVATE KEY----\\n<private key>\\n-----END PRIVATE KEY-----\\n",
3737
"client_email": "fleet-calendar-events@fleet-in-your-calendar.iam.gserviceaccount.com",
3838
"client_id": "<client id>",
3939
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
@@ -58,6 +58,16 @@ interface ICalendarsFormData {
5858
apiKeyJson?: string;
5959
}
6060

61+
// Used to surface error.message in UI of unknown error type
62+
type ErrorWithMessage = {
63+
message: string;
64+
[key: string]: unknown;
65+
};
66+
67+
const isErrorWithMessage = (error: unknown): error is ErrorWithMessage => {
68+
return (error as ErrorWithMessage).message !== undefined;
69+
};
70+
6171
const baseClass = "calendars-integration";
6272

6373
const Calendars = (): JSX.Element => {
@@ -103,7 +113,18 @@ const Calendars = (): JSX.Element => {
103113
errors.apiKeyJson = "API key JSON must be present";
104114
}
105115
if (!curFormData.domain && !!curFormData.apiKeyJson) {
106-
errors.apiKeyJson = "Domain must be present";
116+
errors.domain = "Domain must be present";
117+
}
118+
if (curFormData.apiKeyJson) {
119+
try {
120+
JSON.parse(curFormData.apiKeyJson);
121+
} catch (e: unknown) {
122+
if (isErrorWithMessage(e)) {
123+
errors.apiKeyJson = e.message.toString();
124+
} else {
125+
throw e;
126+
}
127+
}
107128
}
108129
return errors;
109130
};
@@ -277,6 +298,7 @@ const Calendars = (): JSX.Element => {
277298
placeholder={API_KEY_JSON_PLACEHOLDER}
278299
ignore1password
279300
inputClassName={`${baseClass}__api-key-json`}
301+
error={formErrors.apiKeyJson}
280302
/>
281303
<InputField
282304
label="Primary domain"
@@ -301,12 +323,13 @@ const Calendars = (): JSX.Element => {
301323
/>
302324
</>
303325
}
326+
error={formErrors.domain}
304327
/>
305328
<Button
306329
type="submit"
307330
variant="brand"
308331
disabled={Object.keys(formErrors).length > 0}
309-
className="save-loading button-wrap"
332+
className="save-loading"
310333
isLoading={isUpdatingSettings}
311334
>
312335
Save
@@ -378,6 +401,10 @@ const Calendars = (): JSX.Element => {
378401
</li>
379402
</ul>
380403
</p>
404+
<p>
405+
You&apos;re ready to automatically schedule calendar events for end
406+
users.
407+
</p>
381408
</div>
382409
</>
383410
);

frontend/pages/admin/IntegrationsPage/cards/Calendars/_styles.scss

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
color: $core-fleet-black;
55
}
66

7+
p {
8+
margin: $pad-large 0;
9+
}
10+
711
ui {
812
margin-block-start: $pad-small;
913
}
@@ -30,6 +34,7 @@
3034

3135
#oauth-scopes {
3236
font-family: "SourceCodePro", $monospace;
37+
color: $core-fleet-black;
3338
min-height: 80px;
3439
padding: $pad-medium;
3540
padding-right: $pad-xxlarge;

0 commit comments

Comments
 (0)