message push config
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Access } from "@/domain/access";
|
||||
import { ConfigData } from ".";
|
||||
import { Setting } from "@/domain/settings";
|
||||
import { EmailsSetting, Setting } from "@/domain/settings";
|
||||
import { AccessGroup } from "@/domain/access_groups";
|
||||
|
||||
type Action =
|
||||
@@ -57,7 +57,10 @@ export const configReducer = (
|
||||
emails: {
|
||||
...state.emails,
|
||||
content: {
|
||||
emails: [...state.emails.content.emails, action.payload],
|
||||
emails: [
|
||||
...(state.emails.content as EmailsSetting).emails,
|
||||
action.payload,
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
68
ui/src/providers/notify/index.tsx
Normal file
68
ui/src/providers/notify/index.tsx
Normal file
@@ -0,0 +1,68 @@
|
||||
import { NotifyChannel, Setting } from "@/domain/settings";
|
||||
import { getSetting } from "@/repository/settings";
|
||||
import {
|
||||
ReactNode,
|
||||
useContext,
|
||||
createContext,
|
||||
useEffect,
|
||||
useReducer,
|
||||
useCallback,
|
||||
} from "react";
|
||||
import { notifyReducer } from "./reducer";
|
||||
|
||||
export type NotifyContext = {
|
||||
config: Setting;
|
||||
setChannel: (data: { channel: string; data: NotifyChannel }) => void;
|
||||
setChannels: (data: Setting) => void;
|
||||
};
|
||||
|
||||
const Context = createContext({} as NotifyContext);
|
||||
|
||||
export const useNotify = () => useContext(Context);
|
||||
interface ContainerProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const NotifyProvider = ({ children }: ContainerProps) => {
|
||||
const [notify, dispatchNotify] = useReducer(notifyReducer, {});
|
||||
|
||||
useEffect(() => {
|
||||
const featchData = async () => {
|
||||
const chanels = await getSetting("notifyChannels");
|
||||
dispatchNotify({
|
||||
type: "SET_CHANNELS",
|
||||
payload: chanels,
|
||||
});
|
||||
};
|
||||
featchData();
|
||||
}, []);
|
||||
|
||||
const setChannel = useCallback(
|
||||
(data: { channel: string; data: NotifyChannel }) => {
|
||||
dispatchNotify({
|
||||
type: "SET_CHANNEL",
|
||||
payload: data,
|
||||
});
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const setChannels = useCallback((setting: Setting) => {
|
||||
dispatchNotify({
|
||||
type: "SET_CHANNELS",
|
||||
payload: setting,
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Context.Provider
|
||||
value={{
|
||||
config: notify,
|
||||
setChannel,
|
||||
setChannels,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Context.Provider>
|
||||
);
|
||||
};
|
||||
35
ui/src/providers/notify/reducer.tsx
Normal file
35
ui/src/providers/notify/reducer.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import { NotifyChannel, Setting } from "@/domain/settings";
|
||||
|
||||
type Action =
|
||||
| {
|
||||
type: "SET_CHANNEL";
|
||||
payload: {
|
||||
channel: string;
|
||||
data: NotifyChannel;
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: "SET_CHANNELS";
|
||||
payload: Setting;
|
||||
};
|
||||
|
||||
export const notifyReducer = (state: Setting, action: Action) => {
|
||||
switch (action.type) {
|
||||
case "SET_CHANNEL": {
|
||||
const channel = action.payload.channel;
|
||||
return {
|
||||
...state,
|
||||
content: {
|
||||
...state.content,
|
||||
[channel]: action.payload.data,
|
||||
},
|
||||
};
|
||||
}
|
||||
case "SET_CHANNELS": {
|
||||
return { ...action.payload };
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user