MCPcopy Create free account
hub / github.com/Recordscript/recordscript / EmailConfigurator

Function EmailConfigurator

src/App.tsx:107–285  ·  view source on GitHub ↗
(props: P)

Source from the content-addressed store, hash-verified

105}
106
107function EmailConfigurator<P extends { on_save: () => void }>(props: P) {
108 const [smtp_config, { refetch: update_smtp_config }] = createInvokeResource<
109 SMTPConfig
110 >("get_smtp_config");
111
112 const error = new ReactiveMap<"host" | "port" | "username" | "password" | "from", string>();
113
114 const [host, set_host] = createSignal("");
115 const [port, set_port] = createSignal<number | null>(null);
116 const [username, set_username] = createSignal("");
117 const [password, set_password] = createSignal("");
118 const [from, set_from] = createSignal("");
119
120 async function set_config(config: SMTPConfig) {
121 await invoke("set_smtp_config", { config });
122 update_smtp_config();
123 }
124
125 async function on_save() {
126 const has_error = Array.from(error.keys()).length !== 0;
127
128 if (has_error) {
129 emit("app://notification", {
130 "type": "error",
131 "value": "Unable to save because some of the fields are not valid"
132 });
133
134 return;
135 }
136
137 const config = smtp_config()!;
138
139 await set_config({
140 host: host() || config.host,
141 port: port() || config.port,
142 username: username() || config.username,
143 password: password() || config.password,
144 from: from() || config.from,
145 });
146
147 props.on_save();
148 }
149
150 return (
151 <div class="p-2 h-full flex flex-col">
152 <h2 class="text-xl font-bold h-fit">Email Configuration</h2>
153 <hr class="my-2" />
154 <div class="flex flex-col gap-1">
155 <section class="flex items-center gap-2">
156 <h3 class="text-sm font-bold my-0 h-fit w-52">
157 SMTP Host
158 </h3>
159 <div class="flex flex-col w-full">
160 <span class="text-xs z-30 bg-white w-fit text-red-800">
161 {error.get("host")}
162 </span>
163 <input
164 type="text"

Callers 1

Calls 3

createInvokeResourceFunction · 0.85
getMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected