2023-11-09 15:33:31 +00:00
|
|
|
import axios, { isAxiosError, ResponseType as AxiosResponseType } from "axios";
|
2021-08-03 19:42:48 +00:00
|
|
|
import URL_PREFIX from "router/url_prefix";
|
2023-11-09 15:33:31 +00:00
|
|
|
import { authToken } from "utilities/local";
|
2021-08-03 19:42:48 +00:00
|
|
|
|
2023-11-09 15:33:31 +00:00
|
|
|
export const sendRequest = async (
|
2022-08-16 15:54:41 +00:00
|
|
|
method: "GET" | "POST" | "PATCH" | "DELETE" | "HEAD",
|
2021-08-03 19:42:48 +00:00
|
|
|
path: string,
|
2022-07-19 19:28:06 +00:00
|
|
|
data?: unknown,
|
UI: 9274 unenroll mdm modal (#9539)
# Addresses #9274
https://www.loom.com/share/2edd946cbd424af2b960801cc505ac85
## Button and permissions:
- no permission, enrolled, online: <img width="1131" alt="no permission,
enrolled, online"
src="https://user-images.githubusercontent.com/61553566/215197330-abc1606d-bf0a-44ec-b2de-2ef687bd529b.png">
- permission, enrolled, online: <img width="1131" alt="permission,
enrolled, online"
src="https://user-images.githubusercontent.com/61553566/215197443-a1353b9b-10dd-408b-8295-56029f2df4c3.png">
- permission, enrolled, offline: <img width="1131" alt="permission,
enrolled, offline"
src="https://user-images.githubusercontent.com/61553566/215197544-b2a997a7-09e5-4f8a-b723-af587b61a90d.png">
- not enrolled: <img width="1131" alt="not enrolled"
src="https://user-images.githubusercontent.com/61553566/215197630-87f99cb3-63a9-45ce-bc85-57a45d54cae0.png">
## Modal
- <img width="672" alt="modal"
src="https://user-images.githubusercontent.com/61553566/215214640-96670a23-d927-4213-a8fa-89411279c075.png">
- <img width="672" alt="Screenshot 2023-01-27 at 2 12 42 PM"
src="https://user-images.githubusercontent.com/61553566/215215098-40d29556-3b73-4f52-a4ae-cc8b09122f5d.png">
- <img width="672" alt="Screenshot 2023-01-27 at 2 17 48 PM"
src="https://user-images.githubusercontent.com/61553566/215216304-b9362b13-f37f-4454-81b5-423f6fc72280.png">
- <img width="787" alt="success-shot"
src="https://user-images.githubusercontent.com/61553566/215236373-be7b1970-662d-47e6-ac59-f51eff344fcd.png">
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [x] Changes file added for user-visible changes in `changes/`
- [x] Updated test inventory
- [x] Manual QA for all new/changed functionality
---------
Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-01-30 23:59:02 +00:00
|
|
|
responseType: AxiosResponseType = "json",
|
2023-11-09 15:33:31 +00:00
|
|
|
timeout?: number,
|
|
|
|
skipParseError?: boolean
|
2023-11-03 15:32:41 +00:00
|
|
|
) => {
|
2021-08-03 19:42:48 +00:00
|
|
|
const { origin } = global.window.location;
|
|
|
|
|
|
|
|
const url = `${origin}${URL_PREFIX}/api${path}`;
|
2023-11-03 15:32:41 +00:00
|
|
|
const token = authToken();
|
2021-08-03 19:42:48 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await axios({
|
|
|
|
method,
|
|
|
|
url,
|
|
|
|
data,
|
2022-07-19 19:28:06 +00:00
|
|
|
responseType,
|
UI: 9274 unenroll mdm modal (#9539)
# Addresses #9274
https://www.loom.com/share/2edd946cbd424af2b960801cc505ac85
## Button and permissions:
- no permission, enrolled, online: <img width="1131" alt="no permission,
enrolled, online"
src="https://user-images.githubusercontent.com/61553566/215197330-abc1606d-bf0a-44ec-b2de-2ef687bd529b.png">
- permission, enrolled, online: <img width="1131" alt="permission,
enrolled, online"
src="https://user-images.githubusercontent.com/61553566/215197443-a1353b9b-10dd-408b-8295-56029f2df4c3.png">
- permission, enrolled, offline: <img width="1131" alt="permission,
enrolled, offline"
src="https://user-images.githubusercontent.com/61553566/215197544-b2a997a7-09e5-4f8a-b723-af587b61a90d.png">
- not enrolled: <img width="1131" alt="not enrolled"
src="https://user-images.githubusercontent.com/61553566/215197630-87f99cb3-63a9-45ce-bc85-57a45d54cae0.png">
## Modal
- <img width="672" alt="modal"
src="https://user-images.githubusercontent.com/61553566/215214640-96670a23-d927-4213-a8fa-89411279c075.png">
- <img width="672" alt="Screenshot 2023-01-27 at 2 12 42 PM"
src="https://user-images.githubusercontent.com/61553566/215215098-40d29556-3b73-4f52-a4ae-cc8b09122f5d.png">
- <img width="672" alt="Screenshot 2023-01-27 at 2 17 48 PM"
src="https://user-images.githubusercontent.com/61553566/215216304-b9362b13-f37f-4454-81b5-423f6fc72280.png">
- <img width="787" alt="success-shot"
src="https://user-images.githubusercontent.com/61553566/215236373-be7b1970-662d-47e6-ac59-f51eff344fcd.png">
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [x] Changes file added for user-visible changes in `changes/`
- [x] Updated test inventory
- [x] Manual QA for all new/changed functionality
---------
Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-01-30 23:59:02 +00:00
|
|
|
timeout,
|
2021-08-03 19:42:48 +00:00
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-11-03 15:32:41 +00:00
|
|
|
return response.data;
|
2021-08-03 19:42:48 +00:00
|
|
|
} catch (error) {
|
2023-11-09 15:33:31 +00:00
|
|
|
if (skipParseError) {
|
|
|
|
return Promise.reject(error);
|
|
|
|
}
|
|
|
|
let reason: unknown | undefined;
|
|
|
|
if (isAxiosError(error)) {
|
|
|
|
reason = error.response || error.message || error.code;
|
|
|
|
}
|
2023-11-03 15:32:41 +00:00
|
|
|
return Promise.reject(
|
2023-11-09 15:33:31 +00:00
|
|
|
reason || `send request: parse server error: ${error}`
|
2023-11-03 15:32:41 +00:00
|
|
|
);
|
2021-08-03 19:42:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default sendRequest;
|