mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-19 11:26:37 +00:00
add supporer key program
This commit is contained in:
46
src/providers/SupporterStatusProvider.tsx
Normal file
46
src/providers/SupporterStatusProvider.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import SupportStatusContext, {
|
||||
SupporterStatus
|
||||
} from "@app/contexts/supporterStatusContext";
|
||||
import { useState } from "react";
|
||||
|
||||
interface ProviderProps {
|
||||
children: React.ReactNode;
|
||||
supporterStatus: SupporterStatus | null;
|
||||
}
|
||||
|
||||
export function SupporterStatusProvider({
|
||||
children,
|
||||
supporterStatus
|
||||
}: ProviderProps) {
|
||||
const [supporterStatusState, setSupporterStatusState] =
|
||||
useState<SupporterStatus | null>(supporterStatus);
|
||||
|
||||
const updateSupporterStatus = (
|
||||
updatedSupporterStatus: Partial<SupporterStatus>
|
||||
) => {
|
||||
setSupporterStatusState((prev) => {
|
||||
if (!prev) {
|
||||
return updatedSupporterStatus as SupporterStatus;
|
||||
}
|
||||
return {
|
||||
...prev,
|
||||
...updatedSupporterStatus
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<SupportStatusContext.Provider
|
||||
value={{
|
||||
supporterStatus: supporterStatusState,
|
||||
updateSupporterStatus
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</SupportStatusContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export default SupporterStatusProvider;
|
||||
Reference in New Issue
Block a user