@insforge/react 1.0.5-dev.2 → 1.0.5-dev.4
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/atoms.cjs.map +1 -1
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +27 -78
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +27 -78
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +10 -9
- package/dist/hooks.d.ts +10 -9
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +27 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -78
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/components.cjs
CHANGED
|
@@ -4895,30 +4895,17 @@ var ProfileSpinner = styled.div`
|
|
|
4895
4895
|
}
|
|
4896
4896
|
}
|
|
4897
4897
|
`;
|
|
4898
|
-
var READ_ONLY_FIELDS = ["id", "email", "avatar_url", "created_at", "updated_at"];
|
|
4899
|
-
var HIDDEN_FIELDS = ["id", "avatar_url"];
|
|
4900
|
-
function formatFieldLabel(key) {
|
|
4901
|
-
return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase();
|
|
4902
|
-
}
|
|
4903
4898
|
function UserProfileModal({ onClose, onError }) {
|
|
4904
4899
|
const { user, updateUser, isLoaded } = useInsforge();
|
|
4905
4900
|
const [isEditing, setIsEditing] = React2.useState(false);
|
|
4906
4901
|
const [isSaving, setIsSaving] = React2.useState(false);
|
|
4907
4902
|
const [imageError, setImageError] = React2.useState(false);
|
|
4908
|
-
const [
|
|
4903
|
+
const [name, setName] = React2.useState("");
|
|
4909
4904
|
React2.useEffect(() => {
|
|
4910
|
-
if (user) {
|
|
4911
|
-
|
|
4912
|
-
if (user.profile) {
|
|
4913
|
-
Object.entries(user.profile).forEach(([key, value]) => {
|
|
4914
|
-
if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
|
|
4915
|
-
initialData[key] = value;
|
|
4916
|
-
}
|
|
4917
|
-
});
|
|
4918
|
-
}
|
|
4919
|
-
setFormData(initialData);
|
|
4905
|
+
if (user?.profile?.name) {
|
|
4906
|
+
setName(user.profile.name);
|
|
4920
4907
|
}
|
|
4921
|
-
}, [user]);
|
|
4908
|
+
}, [user?.profile?.name]);
|
|
4922
4909
|
React2.useEffect(() => {
|
|
4923
4910
|
setImageError(false);
|
|
4924
4911
|
const avatarUrl = user?.profile?.avatar_url;
|
|
@@ -4940,26 +4927,11 @@ function UserProfileModal({ onClose, onError }) {
|
|
|
4940
4927
|
};
|
|
4941
4928
|
void checkImageUrl();
|
|
4942
4929
|
}, [user?.profile?.avatar_url]);
|
|
4943
|
-
const handleFieldChange = React2.useCallback((key, value) => {
|
|
4944
|
-
setFormData((prev2) => ({
|
|
4945
|
-
...prev2,
|
|
4946
|
-
[key]: value
|
|
4947
|
-
}));
|
|
4948
|
-
}, []);
|
|
4949
4930
|
const handleSave = React2.useCallback(async () => {
|
|
4950
4931
|
if (!user) return;
|
|
4951
4932
|
setIsSaving(true);
|
|
4952
4933
|
try {
|
|
4953
|
-
const { name
|
|
4954
|
-
const updateData = {
|
|
4955
|
-
profile: {
|
|
4956
|
-
name
|
|
4957
|
-
}
|
|
4958
|
-
};
|
|
4959
|
-
if (Object.keys(dynamicFields).length > 0) {
|
|
4960
|
-
updateData.profile = dynamicFields;
|
|
4961
|
-
}
|
|
4962
|
-
const result = await updateUser(updateData);
|
|
4934
|
+
const result = await updateUser({ profile: { name } });
|
|
4963
4935
|
if (result?.error) {
|
|
4964
4936
|
onError?.(result.error);
|
|
4965
4937
|
} else {
|
|
@@ -4970,23 +4942,11 @@ function UserProfileModal({ onClose, onError }) {
|
|
|
4970
4942
|
} finally {
|
|
4971
4943
|
setIsSaving(false);
|
|
4972
4944
|
}
|
|
4973
|
-
}, [user,
|
|
4945
|
+
}, [user, name, updateUser, onError]);
|
|
4974
4946
|
const handleCancel = React2.useCallback(() => {
|
|
4975
|
-
|
|
4976
|
-
const resetData = {
|
|
4977
|
-
name: user.profile?.name || ""
|
|
4978
|
-
};
|
|
4979
|
-
if (user.profile) {
|
|
4980
|
-
Object.entries(user.profile).forEach(([key, value]) => {
|
|
4981
|
-
if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
|
|
4982
|
-
resetData[key] = value;
|
|
4983
|
-
}
|
|
4984
|
-
});
|
|
4985
|
-
}
|
|
4986
|
-
setFormData(resetData);
|
|
4987
|
-
}
|
|
4947
|
+
setName(user?.profile?.name || "");
|
|
4988
4948
|
setIsEditing(false);
|
|
4989
|
-
}, [user]);
|
|
4949
|
+
}, [user?.profile?.name]);
|
|
4990
4950
|
const handleOverlayClick = React2.useCallback(
|
|
4991
4951
|
(e) => {
|
|
4992
4952
|
if (e.target === e.currentTarget) {
|
|
@@ -5012,24 +4972,6 @@ function UserProfileModal({ onClose, onError }) {
|
|
|
5012
4972
|
return null;
|
|
5013
4973
|
}
|
|
5014
4974
|
const initials = user.profile?.name ? user.profile.name.charAt(0).toUpperCase() : user.email.split("@")[0].slice(0, 2).toUpperCase();
|
|
5015
|
-
const fields = [];
|
|
5016
|
-
fields.push({ key: "email", value: user.email, readOnly: true });
|
|
5017
|
-
fields.push({
|
|
5018
|
-
key: "name",
|
|
5019
|
-
value: isEditing ? formData.name || "" : user.profile?.name || "",
|
|
5020
|
-
readOnly: false
|
|
5021
|
-
});
|
|
5022
|
-
if (user.profile) {
|
|
5023
|
-
Object.entries(user.profile).forEach(([key, value]) => {
|
|
5024
|
-
if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
|
|
5025
|
-
fields.push({
|
|
5026
|
-
key,
|
|
5027
|
-
value: isEditing ? formData[key] ?? value : value,
|
|
5028
|
-
readOnly: READ_ONLY_FIELDS.includes(key)
|
|
5029
|
-
});
|
|
5030
|
-
}
|
|
5031
|
-
});
|
|
5032
|
-
}
|
|
5033
4975
|
return /* @__PURE__ */ jsxRuntime.jsx(ProfileModalOverlay, { onClick: handleOverlayClick, children: /* @__PURE__ */ jsxRuntime.jsxs(ProfileModalContainer, { onClick: (e) => e.stopPropagation(), children: [
|
|
5034
4976
|
/* @__PURE__ */ jsxRuntime.jsxs(ProfileModalHeader, { children: [
|
|
5035
4977
|
/* @__PURE__ */ jsxRuntime.jsx(ProfileModalTitle, { children: "Profile" }),
|
|
@@ -5044,18 +4986,25 @@ function UserProfileModal({ onClose, onError }) {
|
|
|
5044
4986
|
onError: () => setImageError(true)
|
|
5045
4987
|
}
|
|
5046
4988
|
) : initials }) }),
|
|
5047
|
-
/* @__PURE__ */ jsxRuntime.
|
|
5048
|
-
/* @__PURE__ */ jsxRuntime.
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
4989
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ProfileFieldsContainer, { children: [
|
|
4990
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ProfileField, { children: [
|
|
4991
|
+
/* @__PURE__ */ jsxRuntime.jsx(ProfileFieldLabel, { children: "email" }),
|
|
4992
|
+
/* @__PURE__ */ jsxRuntime.jsx(ProfileFieldValue, { children: user.email })
|
|
4993
|
+
] }),
|
|
4994
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ProfileField, { children: [
|
|
4995
|
+
/* @__PURE__ */ jsxRuntime.jsx(ProfileFieldLabel, { children: "name" }),
|
|
4996
|
+
isEditing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4997
|
+
ProfileFieldInput,
|
|
4998
|
+
{
|
|
4999
|
+
type: "text",
|
|
5000
|
+
value: name,
|
|
5001
|
+
onChange: (e) => setName(e.target.value),
|
|
5002
|
+
disabled: isSaving,
|
|
5003
|
+
placeholder: "Enter your name"
|
|
5004
|
+
}
|
|
5005
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(ProfileFieldValue, { children: user.profile?.name || "-" })
|
|
5006
|
+
] })
|
|
5007
|
+
] })
|
|
5059
5008
|
] }),
|
|
5060
5009
|
/* @__PURE__ */ jsxRuntime.jsx(ProfileModalFooter, { children: isEditing ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5061
5010
|
/* @__PURE__ */ jsxRuntime.jsx(ProfileButton, { onClick: handleCancel, disabled: isSaving, children: "Cancel" }),
|