-
+ );
+};
+const SSLProviderZeroSSLForm = () => {
+ const { t } = useTranslation();
+
+ const { setting, onSubmit } = useSSLProviderContext();
+
+ const formSchema = z.object({
+ kind: z.literal("zerossl"),
+ eabKid: z.string().min(1, { message: t("settings.ca.eab_kid_hmac_key.errmsg.empty") }),
+ eabHmacKey: z.string().min(1, { message: t("settings.ca.eab_kid_hmac_key.errmsg.empty") }),
+ });
+
+ const form = useForm
>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ kind: "zerossl",
+ eabKid: "",
+ eabHmacKey: "",
+ },
+ });
+
+ useEffect(() => {
+ if (setting.content) {
+ const content = setting.content;
+
+ form.reset({
+ eabKid: getConfigStr(content, "zerossl", "eabKid"),
+ eabHmacKey: getConfigStr(content, "zerossl", "eabHmacKey"),
+ });
+ }
+ }, [setting]);
+
+ const onLocalSubmit = async (data: z.infer) => {
+ const newData = produce(setting, (draft) => {
+ if (!draft.content) {
+ draft.content = {
+ provider: "zerossl",
+ config: {
+ zerossl: {},
+ },
+ };
+ }
+
+ draft.content.config.zerossl = {
+ eabKid: data.eabKid,
+ eabHmacKey: data.eabHmacKey,
+ };
+ });
+ onSubmit(newData);
+ };
+
+ return (
+
+
+ );
+};
+
+const SSLProviderGtsForm = () => {
+ const { t } = useTranslation();
+
+ const { setting, onSubmit } = useSSLProviderContext();
+
+ const formSchema = z.object({
+ kind: z.literal("gts"),
+ eabKid: z.string().min(1, { message: t("settings.ca.eab_kid_hmac_key.errmsg.empty") }),
+ eabHmacKey: z.string().min(1, { message: t("settings.ca.eab_kid_hmac_key.errmsg.empty") }),
+ });
+
+ const form = useForm>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ kind: "gts",
+ eabKid: "",
+ eabHmacKey: "",
+ },
+ });
+
+ useEffect(() => {
+ if (setting.content) {
+ const content = setting.content;
+
+ form.reset({
+ eabKid: getConfigStr(content, "gts", "eabKid"),
+ eabHmacKey: getConfigStr(content, "gts", "eabHmacKey"),
+ });
+ }
+ }, [setting]);
+
+ const onLocalSubmit = async (data: z.infer) => {
+ const newData = produce(setting, (draft) => {
+ if (!draft.content) {
+ draft.content = {
+ provider: "gts",
+ config: {
+ zerossl: {},
+ },
+ };
+ }
+
+ draft.content.config.gts = {
+ eabKid: data.eabKid,
+ eabHmacKey: data.eabHmacKey,
+ };
+ });
+ onSubmit(newData);
+ };
+
+ return (
+
+
+ );
+};
+
export default SSLProvider;
diff --git a/ui/src/providers/config/index.tsx b/ui/src/providers/config/index.tsx
index 0b98c129..d484859c 100644
--- a/ui/src/providers/config/index.tsx
+++ b/ui/src/providers/config/index.tsx
@@ -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;
accessGroups: AccessGroup[];
};
export type ConfigContext = {
config: ConfigData;
- setEmails: (email: Setting) => void;
+ setEmails: (email: Setting) => 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) => {
dispatchConfig({ type: "SET_EMAILS", payload: emails });
}, []);
diff --git a/ui/src/providers/config/reducer.ts b/ui/src/providers/config/reducer.ts
index 0367f009..fd45386c 100644
--- a/ui/src/providers/config/reducer.ts
+++ b/ui/src/providers/config/reducer.ts
@@ -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 }
| { type: "ADD_EMAIL"; payload: string }
| { type: "SET_ACCESS_GROUPS"; payload: AccessGroup[] };
diff --git a/ui/src/providers/notify/index.tsx b/ui/src/providers/notify/index.tsx
index a0e9c195..47f55676 100644
--- a/ui/src/providers/notify/index.tsx
+++ b/ui/src/providers/notify/index.tsx
@@ -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;
setChannel: (data: { channel: string; data: NotifyChannel }) => void;
- setChannels: (data: Setting) => void;
+ setChannels: (data: Setting) => 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");
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) => {
dispatchNotify({
type: "SET_CHANNELS",
payload: setting,
diff --git a/ui/src/providers/notify/reducer.tsx b/ui/src/providers/notify/reducer.tsx
index d5a36efc..8bdaecc9 100644
--- a/ui/src/providers/notify/reducer.tsx
+++ b/ui/src/providers/notify/reducer.tsx
@@ -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;
};
-export const notifyReducer = (state: Setting, action: Action) => {
+export const notifyReducer = (state: Setting, action: Action) => {
switch (action.type) {
case "SET_CHANNEL": {
const channel = action.payload.channel;
diff --git a/ui/src/repository/settings.ts b/ui/src/repository/settings.ts
index 0734cafd..5894c50c 100644
--- a/ui/src/repository/settings.ts
+++ b/ui/src/repository/settings.ts
@@ -1,9 +1,9 @@
-import { Setting } from "@/domain/settings";
+import { EmailsSetting, Setting } from "@/domain/settings";
import { getPb } from "./api";
export const getEmails = async () => {
try {
- const resp = await getPb().collection("settings").getFirstListItem("name='emails'");
+ const resp = await getPb().collection("settings").getFirstListItem>("name='emails'");
return resp;
} catch (e) {
return {
@@ -12,21 +12,21 @@ export const getEmails = async () => {
}
};
-export const getSetting = async (name: string) => {
+export const getSetting = async (name: string) => {
try {
- const resp = await getPb().collection("settings").getFirstListItem(`name='${name}'`);
+ const resp = await getPb().collection("settings").getFirstListItem>(`name='${name}'`);
return resp;
} catch (e) {
- const rs: Setting = {
+ const rs: Setting = {
name: name,
};
return rs;
}
};
-export const update = async (setting: Setting) => {
+export const update = async (setting: Setting) => {
const pb = getPb();
- let resp: Setting;
+ let resp: Setting;
if (setting.id) {
resp = await pb.collection("settings").update(setting.id, setting);
} else {