mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-01 00:06:38 +00:00
♻️ separate org settings page into multiple forms
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,8 @@
|
|||||||
import { GetOrgResponse } from "@server/routers/org";
|
import { GetOrgResponse } from "@server/routers/org";
|
||||||
import { createContext } from "react";
|
import { createContext } from "react";
|
||||||
|
|
||||||
interface OrgContextType {
|
export interface OrgContextType {
|
||||||
org: GetOrgResponse;
|
org: GetOrgResponse;
|
||||||
updateOrg: (updateOrg: Partial<GetOrgResponse>) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const OrgContext = createContext<OrgContextType | undefined>(undefined);
|
const OrgContext = createContext<OrgContextType | undefined>(undefined);
|
||||||
|
|||||||
@@ -10,36 +10,15 @@ interface OrgProviderProps {
|
|||||||
org: GetOrgResponse | null;
|
org: GetOrgResponse | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function OrgProvider({ children, org: serverOrg }: OrgProviderProps) {
|
export function OrgProvider({ children, org }: OrgProviderProps) {
|
||||||
const [org, setOrg] = useState<GetOrgResponse | null>(serverOrg);
|
|
||||||
|
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
if (!org) {
|
if (!org) {
|
||||||
throw new Error(t("orgErrorNoProvided"));
|
throw new Error(t("orgErrorNoProvided"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateOrg = (updatedOrg: Partial<GetOrgResponse>) => {
|
|
||||||
if (!org) {
|
|
||||||
throw new Error(t("orgErrorNoUpdate"));
|
|
||||||
}
|
|
||||||
|
|
||||||
setOrg((prev) => {
|
|
||||||
if (!prev) {
|
|
||||||
return prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...prev,
|
|
||||||
...updatedOrg
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<OrgContext.Provider value={{ org, updateOrg }}>
|
<OrgContext.Provider value={{ org }}>{children}</OrgContext.Provider>
|
||||||
{children}
|
|
||||||
</OrgContext.Provider>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user