fleet/frontend/pages/ManageControlsPage/MacOSSettings/cards/CustomSettings/helpers.ts
Gabriel Hernandez a11e2cce3d
implement UI for uploading, downloading, deleting macOS profiles (#9901)
relates to #9593 

Implements the UI for users to upload, download, and delete macos
profiles


![image](https://user-images.githubusercontent.com/1153709/219685914-6f44e77b-c2cb-47c3-897d-1ba137510fed.png)

- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
- [ ] Added/updated tests
- [x] Manual QA for all new/changed functionality
2023-02-21 15:31:19 +00:00

52 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { AxiosResponse } from "axios";
import { IApiError } from "interfaces/errors";
export const UPLOAD_ERROR_MESSAGES = {
wrongType: {
condition: () => false,
message: "Couldnt upload. The file should be a .mobileconfig file.",
},
identifierExists: {
condition: (reason: string) =>
reason.includes("MDMAppleConfigProfile.PayloadIdentifier"),
message:
"Couldnt upload. A configuration profile with this identifier (PayloadIdentifier) already exists.",
},
nameExists: {
condition: (reason: string) => reason.includes("PayloadDisplayName"),
message:
"Couldnt upload. A configuration profile with this name (PayloadDisplayName) already exists.",
},
encrypted: {
condition: (reason: string) => reason.includes("encrypted"),
message: "Couldnt upload. The file should be unencrypted.",
},
validXML: {
condition: (reason: string) => reason.includes("parsing XML"),
message: "Couldnt upload. The file should include valid XML.",
},
fileVault: {
condition: (reason: string) =>
reason.includes("unsupported PayloadType(s): com.apple.MCX.FileVault2"),
message:
"Couldnt upload. The configuration profile cant include FileVault settings. To control these settings, go to Disk encryption.",
},
default: {
condition: () => false,
message: "Couldnt upload. Please try again.",
},
};
export const getErrorMessage = (err: AxiosResponse<IApiError>) => {
const apiReason = err.data.errors[0].reason;
const error = Object.values(UPLOAD_ERROR_MESSAGES).find((errType) =>
errType.condition(apiReason)
);
if (!error) {
return UPLOAD_ERROR_MESSAGES.default.message;
}
return error.message;
};