moved all of the libracart suff from the old frontend into the new new, also...
This commit is contained in:
parent
f1f4b46b48
commit
add87dca1c
13 changed files with 545 additions and 10 deletions
|
|
@ -45,7 +45,8 @@ export {
|
|||
useFileControllerAPI,
|
||||
useContractAPI, //TODO: update api with resolve, reject
|
||||
useJohnDeereProxyAPI, //TODO: update api with resolve, reject
|
||||
useCNHiProxyAPI //TODO: update api with resolve, reject
|
||||
useCNHiProxyAPI, //TODO: update api with resolve, reject
|
||||
useLibraCartProxyAPI //TODO: update api with resolve, reject
|
||||
} from "./pond/pond";
|
||||
// export { SecurityContext, useSecurity } from "./security";
|
||||
export { SnackbarContext, useSnackbar } from "./Snackbar";
|
||||
|
|
|
|||
137
src/providers/pond/libracartProxyAPI.tsx
Normal file
137
src/providers/pond/libracartProxyAPI.tsx
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
import { AxiosResponse } from "axios";
|
||||
import { useHTTP } from "hooks";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import React, { createContext, PropsWithChildren, useContext } from "react";
|
||||
//import { or } from "utils";
|
||||
import { pondURL } from "./pond";
|
||||
|
||||
export interface ILibraCartProxyAPIContext {
|
||||
//add new organization
|
||||
addAccount: (
|
||||
teamKey: string,
|
||||
userID: string,
|
||||
libracartCode: string,
|
||||
libracartAuth: string,
|
||||
libracartUsername: string
|
||||
) => Promise<AxiosResponse<pond.AddLibraCartAccountResponse>>;
|
||||
//list organizations
|
||||
listAccounts: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
as?: string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
) => Promise<AxiosResponse<pond.ListLibraCartAccountsResponse>>;
|
||||
updateAccount: (
|
||||
key: string,
|
||||
options: pond.DataOption[],
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateLibraCartAccountResponse>>;
|
||||
listFields: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
// order?: "asc" | "desc",
|
||||
// orderBy?: string,
|
||||
// search?: string,
|
||||
as?: string,
|
||||
asRoot?: boolean
|
||||
) => Promise<AxiosResponse<pond.ListLibraCartFieldsResponse>>;
|
||||
}
|
||||
|
||||
export const LibraCartProxyAPIContext = createContext<ILibraCartProxyAPIContext>(
|
||||
{} as ILibraCartProxyAPIContext
|
||||
);
|
||||
|
||||
interface Props {}
|
||||
|
||||
export default function LibraCartProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { post, get, put } = useHTTP();
|
||||
|
||||
const addAccount = (
|
||||
teamKey: string,
|
||||
userID: string,
|
||||
libracartCode: string,
|
||||
libracartAuth: string,
|
||||
libracartUsername: string
|
||||
) => {
|
||||
return post<pond.AddLibraCartAccountResponse>(
|
||||
pondURL(
|
||||
"/libracartAccounts?team=" +
|
||||
teamKey +
|
||||
"&user=" +
|
||||
userID +
|
||||
"&code=" +
|
||||
libracartCode +
|
||||
"&auth=" +
|
||||
libracartAuth +
|
||||
"&libracartUsername=" +
|
||||
libracartUsername
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const listAccounts = (
|
||||
limit: number,
|
||||
offset: number,
|
||||
as?: string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
) => {
|
||||
return get<pond.ListLibraCartAccountsResponse>(
|
||||
pondURL(
|
||||
"/libracartAccounts?limit=" +
|
||||
limit +
|
||||
"&offset=" +
|
||||
offset +
|
||||
(as ? "&as=" + as : "") +
|
||||
(keys ? "&keys=" + keys.join(",") : "") +
|
||||
(types ? "&types=" + types.join(",") : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const listFields = (
|
||||
limit: number,
|
||||
offset: number,
|
||||
// order?: "asc" | "desc",
|
||||
// orderBy?: string,
|
||||
// search?: string,
|
||||
as?: string,
|
||||
asRoot?: boolean
|
||||
) => {
|
||||
return get<pond.ListFieldsResponse>(
|
||||
pondURL(
|
||||
"/libracartFields" +
|
||||
"?limit=" +
|
||||
limit +
|
||||
"&offset=" +
|
||||
offset +
|
||||
(as ? "&as=" + as : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const updateAccount = (key: string, options: pond.DataOption[], as?: string) => {
|
||||
return put<pond.UpdateLibraCartAccountResponse>(
|
||||
pondURL(
|
||||
"/libracartAccounts/" + key + "?options=" + options.toString() + (as ? "&as=" + as : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<LibraCartProxyAPIContext.Provider
|
||||
value={{
|
||||
addAccount,
|
||||
listAccounts,
|
||||
updateAccount,
|
||||
listFields
|
||||
}}>
|
||||
{children}
|
||||
</LibraCartProxyAPIContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export const useLibraCartProxyAPI = () => useContext(LibraCartProxyAPIContext);
|
||||
|
|
@ -35,6 +35,7 @@ import ContractProvider, { useContractAPI } from "./contractAPI";
|
|||
import UsageProvider, { useUsageAPI } from "./usageAPI";
|
||||
import KeyManagerProvider, { useKeyManagerAPI } from "./keyManagerAPI";
|
||||
import JohnDeereProvider, { useJohnDeereProxyAPI } from "./johnDeereProxyAPI";
|
||||
import LibraCartProvider, { useLibraCartProxyAPI } from "./libracartProxyAPI";
|
||||
import CNHiProvider, { useCNHiProxyAPI } from "./cnhiProxyAPI";
|
||||
// import NoteProvider from "providers/noteAPI";
|
||||
|
||||
|
|
@ -86,11 +87,13 @@ export default function PondProvider(props: PropsWithChildren<any>) {
|
|||
<ContractProvider>
|
||||
<JohnDeereProvider>
|
||||
<CNHiProvider>
|
||||
<UsageProvider>
|
||||
<KeyManagerProvider>
|
||||
{children}
|
||||
</KeyManagerProvider>
|
||||
</UsageProvider>
|
||||
<LibraCartProvider>
|
||||
<UsageProvider>
|
||||
<KeyManagerProvider>
|
||||
{children}
|
||||
</KeyManagerProvider>
|
||||
</UsageProvider>
|
||||
</LibraCartProvider>
|
||||
</CNHiProvider>
|
||||
</JohnDeereProvider>
|
||||
</ContractProvider>
|
||||
|
|
@ -163,5 +166,6 @@ export {
|
|||
useUsageAPI,
|
||||
useKeyManagerAPI,
|
||||
useJohnDeereProxyAPI,
|
||||
useCNHiProxyAPI
|
||||
useCNHiProxyAPI,
|
||||
useLibraCartProxyAPI
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue