Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fleet UI: Calendar settings iterations #17779

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const API_KEY_JSON_PLACEHOLDER = `{
"type": "service_account",
"project_id": "fleet-in-your-calendar",
"private_key_id": "<private key id>",
"private_key": "-----BEGIN PRIVATE KEY-----\n<private key>\n-----END PRIVATE KEY-----\n",
"private_key": "-----BEGIN PRIVATE KEY----\\n<private key>\\n-----END PRIVATE KEY-----\\n",
"client_email": "fleet-calendar-events@fleet-in-your-calendar.iam.gserviceaccount.com",
"client_id": "<client id>",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
Expand All @@ -58,6 +58,16 @@ interface ICalendarsFormData {
apiKeyJson?: string;
}

// Used to surface error.message in UI of unknown error type
type ErrorWithMessage = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This is probably something we can have as a utility type/typeguard for use across the UI.

message: string;
[key: string]: unknown;
};

const isErrorWithMessage = (error: unknown): error is ErrorWithMessage => {
return (error as ErrorWithMessage).message !== undefined;
};

const baseClass = "calendars-integration";

const Calendars = (): JSX.Element => {
Expand Down Expand Up @@ -103,7 +113,18 @@ const Calendars = (): JSX.Element => {
errors.apiKeyJson = "API key JSON must be present";
}
if (!curFormData.domain && !!curFormData.apiKeyJson) {
errors.apiKeyJson = "Domain must be present";
errors.domain = "Domain must be present";
}
if (curFormData.apiKeyJson) {
try {
JSON.parse(curFormData.apiKeyJson);
} catch (e: unknown) {
if (isErrorWithMessage(e)) {
errors.apiKeyJson = e.message.toString();
} else {
throw e;
}
}
}
return errors;
};
Expand Down Expand Up @@ -277,6 +298,7 @@ const Calendars = (): JSX.Element => {
placeholder={API_KEY_JSON_PLACEHOLDER}
ignore1password
inputClassName={`${baseClass}__api-key-json`}
error={formErrors.apiKeyJson}
/>
<InputField
label="Primary domain"
Expand All @@ -301,12 +323,13 @@ const Calendars = (): JSX.Element => {
/>
</>
}
error={formErrors.domain}
/>
<Button
type="submit"
variant="brand"
disabled={Object.keys(formErrors).length > 0}
className="save-loading button-wrap"
className="save-loading"
isLoading={isUpdatingSettings}
>
Save
Expand Down Expand Up @@ -378,6 +401,10 @@ const Calendars = (): JSX.Element => {
</li>
</ul>
</p>
<p>
You&apos;re ready to automatically schedule calendar events for end
users.
</p>
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
color: $core-fleet-black;
}

p {
margin: $pad-large 0;
}

ui {
margin-block-start: $pad-small;
}
Expand All @@ -30,6 +34,7 @@

#oauth-scopes {
font-family: "SourceCodePro", $monospace;
color: $core-fleet-black;
RachelElysia marked this conversation as resolved.
Show resolved Hide resolved
min-height: 80px;
padding: $pad-medium;
padding-right: $pad-xxlarge;
Expand Down
Loading