mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +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 { createContext } from "react";
|
||||
|
||||
interface OrgContextType {
|
||||
export interface OrgContextType {
|
||||
org: GetOrgResponse;
|
||||
updateOrg: (updateOrg: Partial<GetOrgResponse>) => void;
|
||||
}
|
||||
|
||||
const OrgContext = createContext<OrgContextType | undefined>(undefined);
|
||||
|
||||
@@ -10,36 +10,15 @@ interface OrgProviderProps {
|
||||
org: GetOrgResponse | null;
|
||||
}
|
||||
|
||||
export function OrgProvider({ children, org: serverOrg }: OrgProviderProps) {
|
||||
const [org, setOrg] = useState<GetOrgResponse | null>(serverOrg);
|
||||
|
||||
export function OrgProvider({ children, org }: OrgProviderProps) {
|
||||
const t = useTranslations();
|
||||
|
||||
if (!org) {
|
||||
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 (
|
||||
<OrgContext.Provider value={{ org, updateOrg }}>
|
||||
{children}
|
||||
</OrgContext.Provider>
|
||||
<OrgContext.Provider value={{ org }}>{children}</OrgContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user