@rspress-theme-anatole/theme-default 0.7.13 → 0.7.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bundle.js +48 -22
  2. package/package.json +3 -3
package/dist/bundle.js CHANGED
@@ -3196,48 +3196,74 @@ function RequestArticleSection({ frontmatter }) {
3196
3196
  const { apiUrl, emailSupport } = siteData;
3197
3197
  const requestArticle = frontmatter?.requestArticle;
3198
3198
 
3199
+ const getNameFromEmail = (email) => {
3200
+ if (!email) return "";
3201
+
3202
+ const user = email.split("@")[0];
3203
+
3204
+ return user
3205
+ .split(/[._-]+/)
3206
+ .filter(Boolean)
3207
+ .map(part => part.charAt(0).toUpperCase() + part.slice(1))
3208
+ .join(" ");
3209
+ };
3210
+
3211
+ const sendEmail = (payload) =>
3212
+ fetch(`${apiUrl}/api/SendEmail`, {
3213
+ method: "POST",
3214
+ headers: { "Content-Type": "application/json" },
3215
+ body: JSON.stringify(payload),
3216
+ });
3217
+
3199
3218
  const handleSubmit = async (event) => {
3200
3219
  event.preventDefault();
3201
3220
 
3202
3221
  const form = event.target;
3203
3222
  const solution = form.querySelector("select")?.value || "";
3204
3223
  const question = form.querySelector('textarea')?.value || "";
3205
- const name = form.querySelector('input[type="text"]')?.value || "Anonymous";
3206
- const email = form.querySelector('input[type="email"]')?.value || "No email provided";
3224
+ const name = form.querySelector('input[type="text"]')?.value;
3225
+ const email = form.querySelector('input[type="email"]')?.value;
3207
3226
  const notify = form.querySelector('input[type="checkbox"]')?.checked || false;
3208
3227
 
3209
- const data = {
3210
- to: emailSupport,
3211
- subject: `[Wiki] New article request for ${solution}`,
3212
- templateName: "default",
3228
+ const mainEmail = {
3229
+ to: emailSupport,
3230
+ subject: `[Wiki] New article request for ${solution}`,
3231
+ templateName: "default",
3232
+ placeholders: {
3233
+ solution,
3234
+ question,
3235
+ requesterName: name || "Anonymous",
3236
+ requesterEmail: email || "No email provided",
3237
+ notifyPreference: notify ? "Yes" : "No"
3238
+ }
3239
+ };
3240
+
3241
+ const autoReplyEmail = {
3242
+ to: email,
3243
+ subject: `Request Received - [Wiki] New article request for ${solution}`,
3244
+ templateName: "auto-reply",
3213
3245
  placeholders: {
3214
- solution: `${solution}`,
3215
- question: `${question}`,
3216
- requesterName: `${name}`,
3217
- requesterEmail: `${email}`,
3218
- notifyPreference: `${notify ? "Yes" : "No"}`
3246
+ user: name || getNameFromEmail(email)
3219
3247
  }
3220
- }
3248
+ };
3221
3249
 
3222
3250
  try {
3223
- const response = await fetch(apiUrl + "/api/SendEmail", {
3224
- method: "POST",
3225
- headers: { "Content-Type": "application/json" },
3226
- body: JSON.stringify(data),
3227
- });
3251
+ const res = await sendEmail(mainEmail);
3252
+ if (!res.ok) throw new Error(`Main email failed: ${res.status}`);
3228
3253
 
3229
- if (!response.ok) {
3230
- throw new Error(`HTTP error! status: ${response.status}`);
3254
+ if (email) {
3255
+ const autoRes = await sendEmail(autoReplyEmail);
3256
+ if (!autoRes.ok) throw new Error(`Auto-reply failed: ${autoRes.status}`);
3231
3257
  }
3258
+
3232
3259
  alert("✅ Sent email successfully!");
3233
3260
  form.reset();
3234
- } catch (error) {
3235
- console.error("Error sending email:", error);
3261
+ } catch (err) {
3262
+ console.error("Error sending email:", err);
3236
3263
  alert("❌ Something went wrong while sending email.");
3237
3264
  }
3238
3265
  };
3239
3266
 
3240
-
3241
3267
  return (requestArticle)
3242
3268
  ? (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
3243
3269
  children: [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rspress-theme-anatole/theme-default",
3
3
  "author": "Anatole Tong",
4
- "version": "0.7.13",
4
+ "version": "0.7.14",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
7
7
  "*.css",
@@ -21,8 +21,8 @@
21
21
  "types": "./dist/bundle.d.ts",
22
22
  "dependencies": {
23
23
  "@mdx-js/react": "2.3.0",
24
- "@rspress-theme-anatole/rspress-plugin-mermaid": "0.7.13",
25
- "@rspress-theme-anatole/shared": "0.7.13",
24
+ "@rspress-theme-anatole/rspress-plugin-mermaid": "0.7.14",
25
+ "@rspress-theme-anatole/shared": "0.7.14",
26
26
  "@rspress/runtime": "1.43.8",
27
27
  "body-scroll-lock": "4.0.0-beta.0",
28
28
  "copy-to-clipboard": "^3.3.3",