gts support

This commit is contained in:
yoan
2024-10-23 13:22:17 +08:00
parent bff18a7be7
commit 8bec234fe8
9 changed files with 447 additions and 167 deletions

View File

@@ -2,7 +2,7 @@ import { createContext, ReactNode, useCallback, useContext, useEffect, useReduce
import { Access } from "@/domain/access";
import { AccessGroup } from "@/domain/access_groups";
import { Setting } from "@/domain/settings";
import { EmailsSetting, Setting } from "@/domain/settings";
import { list } from "@/repository/access";
import { list as getAccessGroups } from "@/repository/access_group";
import { getEmails } from "@/repository/settings";
@@ -10,13 +10,13 @@ import { configReducer } from "./reducer";
export type ConfigData = {
accesses: Access[];
emails: Setting;
emails: Setting<EmailsSetting>;
accessGroups: AccessGroup[];
};
export type ConfigContext = {
config: ConfigData;
setEmails: (email: Setting) => void;
setEmails: (email: Setting<EmailsSetting>) => void;
addAccess: (access: Access) => void;
updateAccess: (access: Access) => void;
deleteAccess: (id: string) => void;
@@ -68,7 +68,7 @@ export const ConfigProvider = ({ children }: ConfigProviderProps) => {
dispatchConfig({ type: "SET_ACCESS_GROUPS", payload: accessGroups });
}, []);
const setEmails = useCallback((emails: Setting) => {
const setEmails = useCallback((emails: Setting<EmailsSetting>) => {
dispatchConfig({ type: "SET_EMAILS", payload: emails });
}, []);

View File

@@ -8,7 +8,7 @@ type Action =
| { type: "DELETE_ACCESS"; payload: string }
| { type: "UPDATE_ACCESS"; payload: Access }
| { type: "SET_ACCESSES"; payload: Access[] }
| { type: "SET_EMAILS"; payload: Setting }
| { type: "SET_EMAILS"; payload: Setting<EmailsSetting> }
| { type: "ADD_EMAIL"; payload: string }
| { type: "SET_ACCESS_GROUPS"; payload: AccessGroup[] };

View File

@@ -1,13 +1,13 @@
import { ReactNode, useContext, createContext, useEffect, useReducer, useCallback } from "react";
import { NotifyChannel, Setting } from "@/domain/settings";
import { NotifyChannel, NotifyChannels, Setting } from "@/domain/settings";
import { getSetting } from "@/repository/settings";
import { notifyReducer } from "./reducer";
export type NotifyContext = {
config: Setting;
config: Setting<NotifyChannels>;
setChannel: (data: { channel: string; data: NotifyChannel }) => void;
setChannels: (data: Setting) => void;
setChannels: (data: Setting<NotifyChannels>) => void;
};
const Context = createContext({} as NotifyContext);
@@ -23,7 +23,7 @@ export const NotifyProvider = ({ children }: NotifyProviderProps) => {
useEffect(() => {
const featchData = async () => {
const chanels = await getSetting("notifyChannels");
const chanels = await getSetting<NotifyChannels>("notifyChannels");
dispatchNotify({
type: "SET_CHANNELS",
payload: chanels,
@@ -39,7 +39,7 @@ export const NotifyProvider = ({ children }: NotifyProviderProps) => {
});
}, []);
const setChannels = useCallback((setting: Setting) => {
const setChannels = useCallback((setting: Setting<NotifyChannels>) => {
dispatchNotify({
type: "SET_CHANNELS",
payload: setting,

View File

@@ -1,4 +1,4 @@
import { NotifyChannel, Setting } from "@/domain/settings";
import { NotifyChannel, NotifyChannels, Setting } from "@/domain/settings";
type Action =
| {
@@ -10,10 +10,10 @@ type Action =
}
| {
type: "SET_CHANNELS";
payload: Setting;
payload: Setting<NotifyChannels>;
};
export const notifyReducer = (state: Setting, action: Action) => {
export const notifyReducer = (state: Setting<NotifyChannels>, action: Action) => {
switch (action.type) {
case "SET_CHANNEL": {
const channel = action.payload.channel;