mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
f12780df45
# 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>
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import axios, {
|
|
AxiosError,
|
|
AxiosResponse,
|
|
ResponseType as AxiosResponseType,
|
|
} from "axios";
|
|
import local from "utilities/local";
|
|
import URL_PREFIX from "router/url_prefix";
|
|
|
|
const sendRequest = async (
|
|
method: "GET" | "POST" | "PATCH" | "DELETE" | "HEAD",
|
|
path: string,
|
|
data?: unknown,
|
|
responseType: AxiosResponseType = "json",
|
|
timeout?: number
|
|
): Promise<any> => {
|
|
const { origin } = global.window.location;
|
|
|
|
const url = `${origin}${URL_PREFIX}/api${path}`;
|
|
const token = local.getItem("auth_token");
|
|
|
|
try {
|
|
const response = await axios({
|
|
method,
|
|
url,
|
|
data,
|
|
responseType,
|
|
timeout,
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
});
|
|
|
|
return Promise.resolve(response.data);
|
|
} catch (error) {
|
|
const axiosError = error as AxiosError;
|
|
return Promise.reject(axiosError.response);
|
|
}
|
|
};
|
|
|
|
// return the first error
|
|
export const getError = (response: unknown): string => {
|
|
const r = response as AxiosResponse;
|
|
return r.data?.errors?.[0]?.reason || ""; // TODO: check if any callers rely on empty return value
|
|
};
|
|
|
|
export default sendRequest;
|