@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.
@@ -183,7 +183,7 @@ interface UserProfileModalProps {
183
183
  }
184
184
  /**
185
185
  * User profile modal component.
186
- * Displays user profile information with edit capability for allowed fields.
186
+ * Displays user profile information with edit capability for name.
187
187
  */
188
188
  declare function UserProfileModal({ onClose, onError }: UserProfileModalProps): react_jsx_runtime.JSX.Element | null;
189
189
 
@@ -183,7 +183,7 @@ interface UserProfileModalProps {
183
183
  }
184
184
  /**
185
185
  * User profile modal component.
186
- * Displays user profile information with edit capability for allowed fields.
186
+ * Displays user profile information with edit capability for name.
187
187
  */
188
188
  declare function UserProfileModal({ onClose, onError }: UserProfileModalProps): react_jsx_runtime.JSX.Element | null;
189
189
 
@@ -4874,30 +4874,17 @@ var ProfileSpinner = styled.div`
4874
4874
  }
4875
4875
  }
4876
4876
  `;
4877
- var READ_ONLY_FIELDS = ["id", "email", "avatar_url", "created_at", "updated_at"];
4878
- var HIDDEN_FIELDS = ["id", "avatar_url"];
4879
- function formatFieldLabel(key) {
4880
- return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase();
4881
- }
4882
4877
  function UserProfileModal({ onClose, onError }) {
4883
4878
  const { user, updateUser, isLoaded } = useInsforge();
4884
4879
  const [isEditing, setIsEditing] = useState(false);
4885
4880
  const [isSaving, setIsSaving] = useState(false);
4886
4881
  const [imageError, setImageError] = useState(false);
4887
- const [formData, setFormData] = useState({});
4882
+ const [name, setName] = useState("");
4888
4883
  useEffect(() => {
4889
- if (user) {
4890
- const initialData = {};
4891
- if (user.profile) {
4892
- Object.entries(user.profile).forEach(([key, value]) => {
4893
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
4894
- initialData[key] = value;
4895
- }
4896
- });
4897
- }
4898
- setFormData(initialData);
4884
+ if (user?.profile?.name) {
4885
+ setName(user.profile.name);
4899
4886
  }
4900
- }, [user]);
4887
+ }, [user?.profile?.name]);
4901
4888
  useEffect(() => {
4902
4889
  setImageError(false);
4903
4890
  const avatarUrl = user?.profile?.avatar_url;
@@ -4919,26 +4906,11 @@ function UserProfileModal({ onClose, onError }) {
4919
4906
  };
4920
4907
  void checkImageUrl();
4921
4908
  }, [user?.profile?.avatar_url]);
4922
- const handleFieldChange = useCallback((key, value) => {
4923
- setFormData((prev2) => ({
4924
- ...prev2,
4925
- [key]: value
4926
- }));
4927
- }, []);
4928
4909
  const handleSave = useCallback(async () => {
4929
4910
  if (!user) return;
4930
4911
  setIsSaving(true);
4931
4912
  try {
4932
- const { name, ...dynamicFields } = formData;
4933
- const updateData = {
4934
- profile: {
4935
- name
4936
- }
4937
- };
4938
- if (Object.keys(dynamicFields).length > 0) {
4939
- updateData.profile = dynamicFields;
4940
- }
4941
- const result = await updateUser(updateData);
4913
+ const result = await updateUser({ profile: { name } });
4942
4914
  if (result?.error) {
4943
4915
  onError?.(result.error);
4944
4916
  } else {
@@ -4949,23 +4921,11 @@ function UserProfileModal({ onClose, onError }) {
4949
4921
  } finally {
4950
4922
  setIsSaving(false);
4951
4923
  }
4952
- }, [user, formData, updateUser, onError]);
4924
+ }, [user, name, updateUser, onError]);
4953
4925
  const handleCancel = useCallback(() => {
4954
- if (user) {
4955
- const resetData = {
4956
- name: user.profile?.name || ""
4957
- };
4958
- if (user.profile) {
4959
- Object.entries(user.profile).forEach(([key, value]) => {
4960
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
4961
- resetData[key] = value;
4962
- }
4963
- });
4964
- }
4965
- setFormData(resetData);
4966
- }
4926
+ setName(user?.profile?.name || "");
4967
4927
  setIsEditing(false);
4968
- }, [user]);
4928
+ }, [user?.profile?.name]);
4969
4929
  const handleOverlayClick = useCallback(
4970
4930
  (e) => {
4971
4931
  if (e.target === e.currentTarget) {
@@ -4991,24 +4951,6 @@ function UserProfileModal({ onClose, onError }) {
4991
4951
  return null;
4992
4952
  }
4993
4953
  const initials = user.profile?.name ? user.profile.name.charAt(0).toUpperCase() : user.email.split("@")[0].slice(0, 2).toUpperCase();
4994
- const fields = [];
4995
- fields.push({ key: "email", value: user.email, readOnly: true });
4996
- fields.push({
4997
- key: "name",
4998
- value: isEditing ? formData.name || "" : user.profile?.name || "",
4999
- readOnly: false
5000
- });
5001
- if (user.profile) {
5002
- Object.entries(user.profile).forEach(([key, value]) => {
5003
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
5004
- fields.push({
5005
- key,
5006
- value: isEditing ? formData[key] ?? value : value,
5007
- readOnly: READ_ONLY_FIELDS.includes(key)
5008
- });
5009
- }
5010
- });
5011
- }
5012
4954
  return /* @__PURE__ */ jsx(ProfileModalOverlay, { onClick: handleOverlayClick, children: /* @__PURE__ */ jsxs(ProfileModalContainer, { onClick: (e) => e.stopPropagation(), children: [
5013
4955
  /* @__PURE__ */ jsxs(ProfileModalHeader, { children: [
5014
4956
  /* @__PURE__ */ jsx(ProfileModalTitle, { children: "Profile" }),
@@ -5023,18 +4965,25 @@ function UserProfileModal({ onClose, onError }) {
5023
4965
  onError: () => setImageError(true)
5024
4966
  }
5025
4967
  ) : initials }) }),
5026
- /* @__PURE__ */ jsx(ProfileFieldsContainer, { children: fields.map(({ key, value, readOnly }) => /* @__PURE__ */ jsxs(ProfileField, { children: [
5027
- /* @__PURE__ */ jsx(ProfileFieldLabel, { children: formatFieldLabel(key) }),
5028
- isEditing && !readOnly ? /* @__PURE__ */ jsx(
5029
- ProfileFieldInput,
5030
- {
5031
- type: "text",
5032
- value: formData[key] ?? value,
5033
- onChange: (e) => handleFieldChange(key, e.target.value),
5034
- disabled: isSaving
5035
- }
5036
- ) : /* @__PURE__ */ jsx(ProfileFieldValue, { children: value || "-" })
5037
- ] }, key)) })
4968
+ /* @__PURE__ */ jsxs(ProfileFieldsContainer, { children: [
4969
+ /* @__PURE__ */ jsxs(ProfileField, { children: [
4970
+ /* @__PURE__ */ jsx(ProfileFieldLabel, { children: "email" }),
4971
+ /* @__PURE__ */ jsx(ProfileFieldValue, { children: user.email })
4972
+ ] }),
4973
+ /* @__PURE__ */ jsxs(ProfileField, { children: [
4974
+ /* @__PURE__ */ jsx(ProfileFieldLabel, { children: "name" }),
4975
+ isEditing ? /* @__PURE__ */ jsx(
4976
+ ProfileFieldInput,
4977
+ {
4978
+ type: "text",
4979
+ value: name,
4980
+ onChange: (e) => setName(e.target.value),
4981
+ disabled: isSaving,
4982
+ placeholder: "Enter your name"
4983
+ }
4984
+ ) : /* @__PURE__ */ jsx(ProfileFieldValue, { children: user.profile?.name || "-" })
4985
+ ] })
4986
+ ] })
5038
4987
  ] }),
5039
4988
  /* @__PURE__ */ jsx(ProfileModalFooter, { children: isEditing ? /* @__PURE__ */ jsxs(Fragment, { children: [
5040
4989
  /* @__PURE__ */ jsx(ProfileButton, { onClick: handleCancel, disabled: isSaving, children: "Cancel" }),