added user profile api

This commit is contained in:
ari committed 2022-08-29 12:51:24 -04:00
1 parent 95ac286b53
commit 416d88b965
7 files changed
+88 -11

No files matched your search

+39 -1
View File
@@ -1,13 +1,15 @@
import { useRef } from "react";
import { AutomationData, BareAutomationData } from "types/automations";
import { API } from "./base";
import { UserProfile } from "./types";
import {
AUTOMTAION_LIST,
AUTOMTAION_ITEM,
AUTOMTAION_ITEM_TAGS,
USER_PROFILE_ROOT,
} from "./paths";
export const useMockAPI = (
export const useAutoMockAPI = (
initialAutos: AutomationData[] = [],
makeRef = useRef,
returnErrors: boolean = false
@@ -105,3 +107,39 @@ export const useMockAPI = (
},
};
};
export const useProfileMockAPI = (
initialProfile: UserProfile = {
lang: "eng",
theme: "dark",
},
makeRef = useRef,
returnErrors: boolean = false
): API => {
const profileRef = makeRef(initialProfile);
return {
async makeCall({ path, method = "POST", data = {} }) {
if (returnErrors) {
return {
ok: false,
error: "Test Error",
};
}
if (path === USER_PROFILE_ROOT) {
if (method === "GET") {
return {
ok: true,
data: JSON.parse(JSON.stringify(profileRef.current)),
} as any;
} else if (method === "PUT") {
profileRef.current = data as any;
return { saved: "" };
}
}
return {
ok: false,
error: "PATH NOT FOUND " + method + ": " + path,
};
},
};
};