dauth-context-react 6.2.0 → 6.3.0
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/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +173 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +173 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/DauthProfileModal.tsx +194 -4
- package/src/index.tsx +2 -0
- package/src/interfaces.ts +8 -0
package/dist/index.mjs
CHANGED
|
@@ -762,6 +762,10 @@ function DauthProfileModal({
|
|
|
762
762
|
const [lastname, setLastname] = useState("");
|
|
763
763
|
const [nickname, setNickname] = useState("");
|
|
764
764
|
const [country, setCountry] = useState("");
|
|
765
|
+
const [telPrefix, setTelPrefix] = useState("");
|
|
766
|
+
const [telSuffix, setTelSuffix] = useState("");
|
|
767
|
+
const [birthDate, setBirthDate] = useState("");
|
|
768
|
+
const [customFieldValues, setCustomFieldValues] = useState({});
|
|
765
769
|
const [populated, setPopulated] = useState(false);
|
|
766
770
|
const [saving, setSaving] = useState(false);
|
|
767
771
|
const [status, setStatus] = useState(null);
|
|
@@ -781,6 +785,16 @@ function DauthProfileModal({
|
|
|
781
785
|
setLastname(user.lastname || "");
|
|
782
786
|
setNickname(user.nickname || "");
|
|
783
787
|
setCountry(user.country || "");
|
|
788
|
+
setTelPrefix(user.telPrefix || "");
|
|
789
|
+
setTelSuffix(user.telSuffix || "");
|
|
790
|
+
setBirthDate(
|
|
791
|
+
user.birthDate ? new Date(user.birthDate).toISOString().split("T")[0] : ""
|
|
792
|
+
);
|
|
793
|
+
const cf = {};
|
|
794
|
+
for (const f of domain.customFields ?? []) {
|
|
795
|
+
cf[f.key] = user.customFields?.[f.key] ?? "";
|
|
796
|
+
}
|
|
797
|
+
setCustomFieldValues(cf);
|
|
784
798
|
setPopulated(true);
|
|
785
799
|
}
|
|
786
800
|
if (!open) {
|
|
@@ -830,8 +844,23 @@ function DauthProfileModal({
|
|
|
830
844
|
);
|
|
831
845
|
const hasChanges = useMemo(() => {
|
|
832
846
|
if (!user?._id) return false;
|
|
833
|
-
|
|
834
|
-
|
|
847
|
+
const origBirthDate = user.birthDate ? new Date(user.birthDate).toISOString().split("T")[0] : "";
|
|
848
|
+
const cfChanged = (domain.customFields ?? []).some(
|
|
849
|
+
(f) => (customFieldValues[f.key] ?? "") !== (user.customFields?.[f.key] ?? "")
|
|
850
|
+
);
|
|
851
|
+
return name !== (user.name || "") || lastname !== (user.lastname || "") || nickname !== (user.nickname || "") || country !== (user.country || "") || telPrefix !== (user.telPrefix || "") || telSuffix !== (user.telSuffix || "") || birthDate !== origBirthDate || cfChanged;
|
|
852
|
+
}, [
|
|
853
|
+
name,
|
|
854
|
+
lastname,
|
|
855
|
+
nickname,
|
|
856
|
+
country,
|
|
857
|
+
telPrefix,
|
|
858
|
+
telSuffix,
|
|
859
|
+
birthDate,
|
|
860
|
+
customFieldValues,
|
|
861
|
+
user,
|
|
862
|
+
domain.customFields
|
|
863
|
+
]);
|
|
835
864
|
const canSave = name.trim().length > 0 && hasChanges && !saving;
|
|
836
865
|
const handleSave = useCallback(async () => {
|
|
837
866
|
setSaving(true);
|
|
@@ -840,6 +869,14 @@ function DauthProfileModal({
|
|
|
840
869
|
if (hasField("lastname")) fields.lastname = lastname;
|
|
841
870
|
if (hasField("nickname")) fields.nickname = nickname;
|
|
842
871
|
if (hasField("country")) fields.country = country;
|
|
872
|
+
if (hasField("tel_prefix"))
|
|
873
|
+
fields.telPrefix = telPrefix;
|
|
874
|
+
if (hasField("tel_suffix"))
|
|
875
|
+
fields.telSuffix = telSuffix;
|
|
876
|
+
if (hasField("birth_date") && birthDate)
|
|
877
|
+
fields.birthDate = birthDate;
|
|
878
|
+
if ((domain.customFields ?? []).length > 0)
|
|
879
|
+
fields.customFields = customFieldValues;
|
|
843
880
|
const ok = await updateUser(fields);
|
|
844
881
|
setSaving(false);
|
|
845
882
|
if (ok) {
|
|
@@ -853,7 +890,19 @@ function DauthProfileModal({
|
|
|
853
890
|
message: "Something went wrong. Please try again."
|
|
854
891
|
});
|
|
855
892
|
}
|
|
856
|
-
}, [
|
|
893
|
+
}, [
|
|
894
|
+
name,
|
|
895
|
+
lastname,
|
|
896
|
+
nickname,
|
|
897
|
+
country,
|
|
898
|
+
telPrefix,
|
|
899
|
+
telSuffix,
|
|
900
|
+
birthDate,
|
|
901
|
+
customFieldValues,
|
|
902
|
+
hasField,
|
|
903
|
+
updateUser,
|
|
904
|
+
domain.customFields
|
|
905
|
+
]);
|
|
857
906
|
const handleDelete = useCallback(async () => {
|
|
858
907
|
setDeleting(true);
|
|
859
908
|
const ok = await deleteAccount();
|
|
@@ -1219,6 +1268,127 @@ function DauthProfileModal({
|
|
|
1219
1268
|
onBlur: inputBlurHandler
|
|
1220
1269
|
}
|
|
1221
1270
|
)
|
|
1271
|
+
] }),
|
|
1272
|
+
(hasField("tel_prefix") || hasField("tel_suffix")) && /* @__PURE__ */ jsxs("div", { style: fieldGroup, children: [
|
|
1273
|
+
/* @__PURE__ */ jsxs("div", { style: label, children: [
|
|
1274
|
+
"Phone",
|
|
1275
|
+
isRequired("tel_prefix") || isRequired("tel_suffix") ? " *" : ""
|
|
1276
|
+
] }),
|
|
1277
|
+
/* @__PURE__ */ jsxs(
|
|
1278
|
+
"div",
|
|
1279
|
+
{
|
|
1280
|
+
style: {
|
|
1281
|
+
display: "flex",
|
|
1282
|
+
gap: 8
|
|
1283
|
+
},
|
|
1284
|
+
children: [
|
|
1285
|
+
hasField("tel_prefix") && /* @__PURE__ */ jsx(
|
|
1286
|
+
"input",
|
|
1287
|
+
{
|
|
1288
|
+
id: "dauth-tel-prefix",
|
|
1289
|
+
type: "text",
|
|
1290
|
+
value: telPrefix,
|
|
1291
|
+
onChange: (e) => setTelPrefix(e.target.value),
|
|
1292
|
+
placeholder: "+34",
|
|
1293
|
+
disabled: saving,
|
|
1294
|
+
style: {
|
|
1295
|
+
...input,
|
|
1296
|
+
width: 80,
|
|
1297
|
+
flexShrink: 0
|
|
1298
|
+
},
|
|
1299
|
+
onFocus: inputFocusHandler,
|
|
1300
|
+
onBlur: inputBlurHandler,
|
|
1301
|
+
"aria-label": "Phone prefix"
|
|
1302
|
+
}
|
|
1303
|
+
),
|
|
1304
|
+
hasField("tel_suffix") && /* @__PURE__ */ jsx(
|
|
1305
|
+
"input",
|
|
1306
|
+
{
|
|
1307
|
+
id: "dauth-tel-suffix",
|
|
1308
|
+
type: "tel",
|
|
1309
|
+
value: telSuffix,
|
|
1310
|
+
onChange: (e) => setTelSuffix(e.target.value),
|
|
1311
|
+
placeholder: "612 345 678",
|
|
1312
|
+
disabled: saving,
|
|
1313
|
+
style: {
|
|
1314
|
+
...input,
|
|
1315
|
+
flex: 1
|
|
1316
|
+
},
|
|
1317
|
+
onFocus: inputFocusHandler,
|
|
1318
|
+
onBlur: inputBlurHandler,
|
|
1319
|
+
"aria-label": "Phone number"
|
|
1320
|
+
}
|
|
1321
|
+
)
|
|
1322
|
+
]
|
|
1323
|
+
}
|
|
1324
|
+
)
|
|
1325
|
+
] }),
|
|
1326
|
+
hasField("birth_date") && /* @__PURE__ */ jsxs("div", { style: fieldGroup, children: [
|
|
1327
|
+
/* @__PURE__ */ jsxs(
|
|
1328
|
+
"label",
|
|
1329
|
+
{
|
|
1330
|
+
htmlFor: "dauth-birthdate",
|
|
1331
|
+
style: label,
|
|
1332
|
+
children: [
|
|
1333
|
+
"Birth date",
|
|
1334
|
+
isRequired("birth_date") ? " *" : ""
|
|
1335
|
+
]
|
|
1336
|
+
}
|
|
1337
|
+
),
|
|
1338
|
+
/* @__PURE__ */ jsx(
|
|
1339
|
+
"input",
|
|
1340
|
+
{
|
|
1341
|
+
id: "dauth-birthdate",
|
|
1342
|
+
type: "date",
|
|
1343
|
+
value: birthDate,
|
|
1344
|
+
onChange: (e) => setBirthDate(e.target.value),
|
|
1345
|
+
disabled: saving,
|
|
1346
|
+
style: input,
|
|
1347
|
+
onFocus: inputFocusHandler,
|
|
1348
|
+
onBlur: inputBlurHandler
|
|
1349
|
+
}
|
|
1350
|
+
)
|
|
1351
|
+
] }),
|
|
1352
|
+
(domain.customFields ?? []).length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1353
|
+
/* @__PURE__ */ jsx("hr", { style: separator }),
|
|
1354
|
+
domain.customFields.map((cf) => /* @__PURE__ */ jsxs(
|
|
1355
|
+
"div",
|
|
1356
|
+
{
|
|
1357
|
+
style: fieldGroup,
|
|
1358
|
+
children: [
|
|
1359
|
+
/* @__PURE__ */ jsxs(
|
|
1360
|
+
"label",
|
|
1361
|
+
{
|
|
1362
|
+
htmlFor: `dauth-cf-${cf.key}`,
|
|
1363
|
+
style: label,
|
|
1364
|
+
children: [
|
|
1365
|
+
cf.label,
|
|
1366
|
+
cf.required ? " *" : ""
|
|
1367
|
+
]
|
|
1368
|
+
}
|
|
1369
|
+
),
|
|
1370
|
+
/* @__PURE__ */ jsx(
|
|
1371
|
+
"input",
|
|
1372
|
+
{
|
|
1373
|
+
id: `dauth-cf-${cf.key}`,
|
|
1374
|
+
type: "text",
|
|
1375
|
+
value: customFieldValues[cf.key] ?? "",
|
|
1376
|
+
onChange: (e) => setCustomFieldValues(
|
|
1377
|
+
(prev) => ({
|
|
1378
|
+
...prev,
|
|
1379
|
+
[cf.key]: e.target.value
|
|
1380
|
+
})
|
|
1381
|
+
),
|
|
1382
|
+
disabled: saving,
|
|
1383
|
+
style: input,
|
|
1384
|
+
onFocus: inputFocusHandler,
|
|
1385
|
+
onBlur: inputBlurHandler
|
|
1386
|
+
}
|
|
1387
|
+
)
|
|
1388
|
+
]
|
|
1389
|
+
},
|
|
1390
|
+
cf.key
|
|
1391
|
+
))
|
|
1222
1392
|
] })
|
|
1223
1393
|
] }),
|
|
1224
1394
|
/* @__PURE__ */ jsx("hr", { style: separator }),
|