put the jd and cnh pages in, still need to test that the re-directs still function as expected with the new platform

This commit is contained in:
csawatzky 2025-04-23 13:25:45 -06:00
parent eb7efada69
commit 424b75afb8
13 changed files with 1393 additions and 64 deletions

View file

@ -43,7 +43,9 @@ export {
useGrainBagAPI,
useTransactionAPI,
useFileControllerAPI,
useContractAPI //TODO: update api with resolve, reject
useContractAPI, //TODO: update api with resolve, reject
useJohnDeereProxyAPI, //TODO: update api with resolve, reject
useCNHiProxyAPI //TODO: update api with resolve, reject
} from "./pond/pond";
// export { SecurityContext, useSecurity } from "./security";
export { SnackbarContext, useSnackbar } from "./Snackbar";

View file

@ -0,0 +1,124 @@
import { AxiosResponse } from "axios";
import { useHTTP } from "hooks";
import { pond } from "protobuf-ts/pond";
import { createContext, PropsWithChildren, useContext } from "react";
//import { or } from "utils";
import { pondURL } from "./pond";
export interface ICNHiProxyAPIContext {
//add new organization
addAccount: (
teamKey: string,
userID: string,
cnhiCode: string,
cnhiUsername: string
) => Promise<AxiosResponse<pond.AddCNHiAccountResponse>>;
//list organizations
listAccounts: (
limit: number,
offset: number,
as?: string,
keys?: string[],
types?: string[]
) => Promise<AxiosResponse<pond.ListCNHiAccountsResponse>>;
updateAccount: (
key: string,
options: pond.DataOption[],
as?: string
) => Promise<AxiosResponse<pond.UpdateCNHiAccountResponse>>;
listFields: (
limit: number,
offset: number,
// order?: "asc" | "desc",
// orderBy?: string,
// search?: string,
as?: string,
asRoot?: boolean
) => Promise<AxiosResponse<pond.ListCNHiFieldsResponse>>;
}
export const CNHiProxyAPIContext = createContext<ICNHiProxyAPIContext>({} as ICNHiProxyAPIContext);
interface Props {}
export default function CNHiProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { post, get, put } = useHTTP();
const addAccount = (teamKey: string, userID: string, cnhiCode: string, cnhiUsername: string) => {
return post<pond.AddCNHiAccountResponse>(
pondURL(
"/cnhiAccounts?team=" +
teamKey +
"&user=" +
userID +
"&code=" +
cnhiCode +
"&cnhiUsername=" +
cnhiUsername
)
);
};
const listAccounts = (
limit: number,
offset: number,
as?: string,
keys?: string[],
types?: string[]
) => {
return get<pond.ListCNHiAccountsResponse>(
pondURL(
"/cnhiAccounts?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(
"/cnhiFields" +
"?limit=" +
limit +
"&offset=" +
offset +
(as ? "&as=" + as : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "")
)
);
};
const updateAccount = (key: string, options: pond.DataOption[], as?: string) => {
return put<pond.UpdateCNHiAccountResponse>(
pondURL("/cnhiAccounts/" + key + "?options=" + options.toString() + (as ? "&as=" + as : ""))
);
};
return (
<CNHiProxyAPIContext.Provider
value={{
addAccount,
listAccounts,
updateAccount,
listFields
}}>
{children}
</CNHiProxyAPIContext.Provider>
);
}
export const useCNHiProxyAPI = () => useContext(CNHiProxyAPIContext);

View file

@ -0,0 +1,127 @@
import { AxiosResponse } from "axios";
import { useHTTP } from "hooks";
import { pond } from "protobuf-ts/pond";
import { createContext, PropsWithChildren, useContext } from "react";
//import { or } from "utils";
import { pondURL } from "./pond";
export interface IJohnDeereProxyAPIContext {
//add new organization
addAccount: (
teamKey: string,
userID: string,
jdCode: string,
jdUserName: string
) => Promise<AxiosResponse<pond.AddJDAccountResponse>>;
//list organizations
listAccounts: (
limit: number,
offset: number,
as?: string,
keys?: string[],
types?: string[]
) => Promise<AxiosResponse<pond.ListJDAccountsResponse>>;
updateAccount: (
key: string,
options: pond.DataOption[],
as?: string
) => Promise<AxiosResponse<pond.UpdateJDAccountResponse>>;
//update organizations
listFields: (
limit: number,
offset: number,
// order?: "asc" | "desc",
// orderBy?: string,
// search?: string,
as?: string,
asRoot?: boolean
) => Promise<AxiosResponse<pond.ListJDFieldsResponse>>;
}
export const JohnDeereProxyAPIContext = createContext<IJohnDeereProxyAPIContext>(
{} as IJohnDeereProxyAPIContext
);
interface Props {}
export default function JohnDeereProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { post, get, put } = useHTTP();
const addAccount = (teamKey: string, userID: string, jdCode: string, jdUserName: string) => {
return post<pond.AddJDAccountResponse>(
pondURL(
"/jdAccounts?team=" +
teamKey +
"&user=" +
userID +
"&code=" +
jdCode +
"&jdUserName=" +
jdUserName
)
);
};
const listAccounts = (
limit: number,
offset: number,
as?: string,
keys?: string[],
types?: string[]
) => {
return get<pond.ListJDAccountsResponse>(
pondURL(
"/jdAccounts?limit=" +
limit +
"&offset=" +
offset +
(as ? "&as=" + as : "") +
(keys ? "&keys=" + keys.join(",") : "") +
(types ? "&types=" + types.join(",") : "")
)
);
};
const updateAccount = (key: string, options: pond.DataOption[], as?: string) => {
return put<pond.UpdateJDAccountResponse>(
pondURL("/jdAccounts/" + key + "?options=" + options.toString() + (as ? "&as=" + as : ""))
);
};
const listFields = (
limit: number,
offset: number,
// order?: "asc" | "desc",
// orderBy?: string,
// search?: string,
as?: string,
asRoot?: boolean
) => {
return get<pond.ListFieldsResponse>(
pondURL(
"/jdFields" +
"?limit=" +
limit +
"&offset=" +
offset +
(as ? "&as=" + as : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "")
)
);
};
return (
<JohnDeereProxyAPIContext.Provider
value={{
addAccount,
listAccounts,
updateAccount,
listFields
}}>
{children}
</JohnDeereProxyAPIContext.Provider>
);
}
export const useJohnDeereProxyAPI = () => useContext(JohnDeereProxyAPIContext);

View file

@ -32,6 +32,8 @@ import PreferenceProvider, {usePreferenceAPI} from "./preferenceAPI";
import TaskProvider, { useTaskAPI } from "./taskAPI";
import DataDogProvider, { useDataDogProxyAPI } from "./datadogProxyAPI";
import ContractProvider, { useContractAPI } from "./contractAPI";
import JohnDeereProvider, { useJohnDeereProxyAPI } from "./johnDeereProxyAPI";
import CNHiProvider, { useCNHiProxyAPI } from "./cnhiProxyAPI";
// import NoteProvider from "providers/noteAPI";
export const pondURL = (partial: string, demo: boolean = false): string => {
@ -80,7 +82,11 @@ export default function PondProvider(props: PropsWithChildren<any>) {
<TaskProvider>
<DataDogProvider>
<ContractProvider>
{children}
<JohnDeereProvider>
<CNHiProvider>
{children}
</CNHiProvider>
</JohnDeereProvider>
</ContractProvider>
</DataDogProvider>
</TaskProvider>
@ -147,5 +153,7 @@ export {
usePreferenceAPI,
useTaskAPI,
useDataDogProxyAPI,
useContractAPI
useContractAPI,
useJohnDeereProxyAPI,
useCNHiProxyAPI
};