mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-10 20:02:26 +00:00
set resource password and remove resource password from dashboard
This commit is contained in:
@@ -1,21 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import ResourceContext from "@app/contexts/resourceContext";
|
||||
import { GetResourceAuthInfoResponse } from "@server/routers/resource";
|
||||
import { GetResourceResponse } from "@server/routers/resource/getResource";
|
||||
import { useState } from "react";
|
||||
|
||||
interface ResourceProviderProps {
|
||||
children: React.ReactNode;
|
||||
resource: GetResourceResponse;
|
||||
authInfo: GetResourceAuthInfoResponse;
|
||||
}
|
||||
|
||||
export function ResourceProvider({
|
||||
children,
|
||||
resource: serverResource,
|
||||
authInfo: serverAuthInfo,
|
||||
}: ResourceProviderProps) {
|
||||
const [resource, setResource] =
|
||||
useState<GetResourceResponse>(serverResource);
|
||||
|
||||
const [authInfo, setAuthInfo] =
|
||||
useState<GetResourceAuthInfoResponse>(serverAuthInfo);
|
||||
|
||||
const updateResource = (updatedResource: Partial<GetResourceResponse>) => {
|
||||
if (!resource) {
|
||||
throw new Error("No resource to update");
|
||||
@@ -33,8 +39,29 @@ export function ResourceProvider({
|
||||
});
|
||||
};
|
||||
|
||||
const updateAuthInfo = (
|
||||
updatedAuthInfo: Partial<GetResourceAuthInfoResponse>
|
||||
) => {
|
||||
if (!authInfo) {
|
||||
throw new Error("No auth info to update");
|
||||
}
|
||||
|
||||
setAuthInfo((prev) => {
|
||||
if (!prev) {
|
||||
return prev;
|
||||
}
|
||||
|
||||
return {
|
||||
...prev,
|
||||
...updatedAuthInfo,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<ResourceContext.Provider value={{ resource, updateResource }}>
|
||||
<ResourceContext.Provider
|
||||
value={{ resource, updateResource, authInfo, updateAuthInfo }}
|
||||
>
|
||||
{children}
|
||||
</ResourceContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user