@szymonpiatek/nextwordpress 0.0.14 → 0.0.15
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.
- package/dist/client/index.cjs +30 -11
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +30 -11
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +30 -11
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +30 -11
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +30 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +30 -2
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +30 -1
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +30 -2
- package/dist/server/index.js.map +1 -1
- package/dist/{types-COJWPg77.d.cts → types-D6rih4G8.d.cts} +7 -1
- package/dist/{types-COJWPg77.d.ts → types-D6rih4G8.d.ts} +7 -1
- package/package.json +1 -1
package/dist/hooks/index.cjs
CHANGED
|
@@ -1470,7 +1470,25 @@ function useWPULike(config, params, swrOptions) {
|
|
|
1470
1470
|
return { data, error, isLoading, vote };
|
|
1471
1471
|
}
|
|
1472
1472
|
|
|
1473
|
+
// src/integrations/restApi/contactForm7/types.ts
|
|
1474
|
+
var CF7Error = class extends Error {
|
|
1475
|
+
constructor(code, status, endpoint, message) {
|
|
1476
|
+
super(message);
|
|
1477
|
+
__publicField(this, "code", code);
|
|
1478
|
+
__publicField(this, "status", status);
|
|
1479
|
+
__publicField(this, "endpoint", endpoint);
|
|
1480
|
+
this.name = "CF7Error";
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
|
|
1473
1484
|
// src/integrations/restApi/contactForm7/queries.ts
|
|
1485
|
+
var statusToCode = {
|
|
1486
|
+
mail_sent: ErrorCode.CF7_MAIL_SENT,
|
|
1487
|
+
mail_failed: ErrorCode.CF7_MAIL_FAILED,
|
|
1488
|
+
validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
|
|
1489
|
+
spam: ErrorCode.CF7_SPAM,
|
|
1490
|
+
aborted: ErrorCode.CF7_ABORTED
|
|
1491
|
+
};
|
|
1474
1492
|
function createCF7Queries(config) {
|
|
1475
1493
|
async function submitForm(formId, data) {
|
|
1476
1494
|
const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
|
|
@@ -1479,26 +1497,27 @@ function createCF7Queries(config) {
|
|
|
1479
1497
|
body.append(key, value);
|
|
1480
1498
|
}
|
|
1481
1499
|
const res = await fetch(url, { method: "POST", body, cache: "no-store" });
|
|
1482
|
-
|
|
1500
|
+
if (!res.ok) {
|
|
1501
|
+
throw new CF7Error(
|
|
1502
|
+
ErrorCode.CF7_MAIL_FAILED,
|
|
1503
|
+
res.status,
|
|
1504
|
+
url,
|
|
1505
|
+
resolveMessage(ErrorCode.CF7_MAIL_FAILED, config.errorMessages)
|
|
1506
|
+
);
|
|
1507
|
+
}
|
|
1508
|
+
const result = await res.json();
|
|
1509
|
+
const code = statusToCode[result.status];
|
|
1510
|
+
return { ...result, message: resolveMessage(code, config.errorMessages) };
|
|
1483
1511
|
}
|
|
1484
1512
|
return { submitForm };
|
|
1485
1513
|
}
|
|
1486
1514
|
|
|
1487
1515
|
// src/hooks/contactForm7/useCF7Submit.ts
|
|
1488
|
-
var statusToCode = {
|
|
1489
|
-
mail_sent: ErrorCode.CF7_MAIL_SENT,
|
|
1490
|
-
mail_failed: ErrorCode.CF7_MAIL_FAILED,
|
|
1491
|
-
validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
|
|
1492
|
-
spam: ErrorCode.CF7_SPAM,
|
|
1493
|
-
aborted: ErrorCode.CF7_ABORTED
|
|
1494
|
-
};
|
|
1495
1516
|
function useCF7Submit(config) {
|
|
1496
1517
|
return useSWRMutation__default.default(
|
|
1497
1518
|
`cf7-submit:${config.serverURL}`,
|
|
1498
1519
|
async (_, { arg }) => {
|
|
1499
|
-
|
|
1500
|
-
const override = config.errorMessages?.[statusToCode[result.status]];
|
|
1501
|
-
return override ? { ...result, message: override } : result;
|
|
1520
|
+
return createCF7Queries(config).submitForm(arg.formId, arg.fields);
|
|
1502
1521
|
}
|
|
1503
1522
|
);
|
|
1504
1523
|
}
|