@insforge/react 1.0.5-dev.1 → 1.0.5-dev.3

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.
@@ -4895,32 +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"];
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 [formData, setFormData] = React2.useState({});
4903
+ const [name, setName] = React2.useState("");
4909
4904
  React2.useEffect(() => {
4910
- if (user) {
4911
- const initialData = {
4912
- name: user.profile?.name || ""
4913
- };
4914
- if (user.profile) {
4915
- Object.entries(user.profile).forEach(([key, value]) => {
4916
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
4917
- initialData[key] = value;
4918
- }
4919
- });
4920
- }
4921
- setFormData(initialData);
4905
+ if (user?.profile?.name) {
4906
+ setName(user.profile.name);
4922
4907
  }
4923
- }, [user]);
4908
+ }, [user?.profile?.name]);
4924
4909
  React2.useEffect(() => {
4925
4910
  setImageError(false);
4926
4911
  const avatarUrl = user?.profile?.avatar_url;
@@ -4942,26 +4927,11 @@ function UserProfileModal({ onClose, onError }) {
4942
4927
  };
4943
4928
  void checkImageUrl();
4944
4929
  }, [user?.profile?.avatar_url]);
4945
- const handleFieldChange = React2.useCallback((key, value) => {
4946
- setFormData((prev2) => ({
4947
- ...prev2,
4948
- [key]: value
4949
- }));
4950
- }, []);
4951
4930
  const handleSave = React2.useCallback(async () => {
4952
4931
  if (!user) return;
4953
4932
  setIsSaving(true);
4954
4933
  try {
4955
- const { name, ...dynamicFields } = formData;
4956
- const updateData = {
4957
- profile: {
4958
- name
4959
- }
4960
- };
4961
- if (Object.keys(dynamicFields).length > 0) {
4962
- updateData.profile = dynamicFields;
4963
- }
4964
- const result = await updateUser(updateData);
4934
+ const result = await updateUser({ profile: { name } });
4965
4935
  if (result?.error) {
4966
4936
  onError?.(result.error);
4967
4937
  } else {
@@ -4972,23 +4942,11 @@ function UserProfileModal({ onClose, onError }) {
4972
4942
  } finally {
4973
4943
  setIsSaving(false);
4974
4944
  }
4975
- }, [user, formData, updateUser, onError]);
4945
+ }, [user, name, updateUser, onError]);
4976
4946
  const handleCancel = React2.useCallback(() => {
4977
- if (user) {
4978
- const resetData = {
4979
- name: user.profile?.name || ""
4980
- };
4981
- if (user.profile) {
4982
- Object.entries(user.profile).forEach(([key, value]) => {
4983
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
4984
- resetData[key] = value;
4985
- }
4986
- });
4987
- }
4988
- setFormData(resetData);
4989
- }
4947
+ setName(user?.profile?.name || "");
4990
4948
  setIsEditing(false);
4991
- }, [user]);
4949
+ }, [user?.profile?.name]);
4992
4950
  const handleOverlayClick = React2.useCallback(
4993
4951
  (e) => {
4994
4952
  if (e.target === e.currentTarget) {
@@ -5014,24 +4972,6 @@ function UserProfileModal({ onClose, onError }) {
5014
4972
  return null;
5015
4973
  }
5016
4974
  const initials = user.profile?.name ? user.profile.name.charAt(0).toUpperCase() : user.email.split("@")[0].slice(0, 2).toUpperCase();
5017
- const fields = [];
5018
- fields.push({ key: "email", value: user.email, readOnly: true });
5019
- fields.push({
5020
- key: "name",
5021
- value: isEditing ? formData.name || "" : user.profile?.name || "",
5022
- readOnly: false
5023
- });
5024
- if (user.profile) {
5025
- Object.entries(user.profile).forEach(([key, value]) => {
5026
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
5027
- fields.push({
5028
- key,
5029
- value: isEditing ? formData[key] ?? value : value,
5030
- readOnly: READ_ONLY_FIELDS.includes(key)
5031
- });
5032
- }
5033
- });
5034
- }
5035
4975
  return /* @__PURE__ */ jsxRuntime.jsx(ProfileModalOverlay, { onClick: handleOverlayClick, children: /* @__PURE__ */ jsxRuntime.jsxs(ProfileModalContainer, { onClick: (e) => e.stopPropagation(), children: [
5036
4976
  /* @__PURE__ */ jsxRuntime.jsxs(ProfileModalHeader, { children: [
5037
4977
  /* @__PURE__ */ jsxRuntime.jsx(ProfileModalTitle, { children: "Profile" }),
@@ -5046,18 +4986,25 @@ function UserProfileModal({ onClose, onError }) {
5046
4986
  onError: () => setImageError(true)
5047
4987
  }
5048
4988
  ) : initials }) }),
5049
- /* @__PURE__ */ jsxRuntime.jsx(ProfileFieldsContainer, { children: fields.map(({ key, value, readOnly }) => /* @__PURE__ */ jsxRuntime.jsxs(ProfileField, { children: [
5050
- /* @__PURE__ */ jsxRuntime.jsx(ProfileFieldLabel, { children: formatFieldLabel(key) }),
5051
- isEditing && !readOnly ? /* @__PURE__ */ jsxRuntime.jsx(
5052
- ProfileFieldInput,
5053
- {
5054
- type: "text",
5055
- value: formData[key] ?? value,
5056
- onChange: (e) => handleFieldChange(key, e.target.value),
5057
- disabled: isSaving
5058
- }
5059
- ) : /* @__PURE__ */ jsxRuntime.jsx(ProfileFieldValue, { children: value || "-" })
5060
- ] }, key)) })
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
+ ] })
5061
5008
  ] }),
5062
5009
  /* @__PURE__ */ jsxRuntime.jsx(ProfileModalFooter, { children: isEditing ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5063
5010
  /* @__PURE__ */ jsxRuntime.jsx(ProfileButton, { onClick: handleCancel, disabled: isSaving, children: "Cancel" }),