@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.
@@ -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,32 +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"];
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
- name: user.profile?.name || ""
4892
- };
4893
- if (user.profile) {
4894
- Object.entries(user.profile).forEach(([key, value]) => {
4895
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
4896
- initialData[key] = value;
4897
- }
4898
- });
4899
- }
4900
- setFormData(initialData);
4884
+ if (user?.profile?.name) {
4885
+ setName(user.profile.name);
4901
4886
  }
4902
- }, [user]);
4887
+ }, [user?.profile?.name]);
4903
4888
  useEffect(() => {
4904
4889
  setImageError(false);
4905
4890
  const avatarUrl = user?.profile?.avatar_url;
@@ -4921,26 +4906,11 @@ function UserProfileModal({ onClose, onError }) {
4921
4906
  };
4922
4907
  void checkImageUrl();
4923
4908
  }, [user?.profile?.avatar_url]);
4924
- const handleFieldChange = useCallback((key, value) => {
4925
- setFormData((prev2) => ({
4926
- ...prev2,
4927
- [key]: value
4928
- }));
4929
- }, []);
4930
4909
  const handleSave = useCallback(async () => {
4931
4910
  if (!user) return;
4932
4911
  setIsSaving(true);
4933
4912
  try {
4934
- const { name, ...dynamicFields } = formData;
4935
- const updateData = {
4936
- profile: {
4937
- name
4938
- }
4939
- };
4940
- if (Object.keys(dynamicFields).length > 0) {
4941
- updateData.profile = dynamicFields;
4942
- }
4943
- const result = await updateUser(updateData);
4913
+ const result = await updateUser({ profile: { name } });
4944
4914
  if (result?.error) {
4945
4915
  onError?.(result.error);
4946
4916
  } else {
@@ -4951,23 +4921,11 @@ function UserProfileModal({ onClose, onError }) {
4951
4921
  } finally {
4952
4922
  setIsSaving(false);
4953
4923
  }
4954
- }, [user, formData, updateUser, onError]);
4924
+ }, [user, name, updateUser, onError]);
4955
4925
  const handleCancel = useCallback(() => {
4956
- if (user) {
4957
- const resetData = {
4958
- name: user.profile?.name || ""
4959
- };
4960
- if (user.profile) {
4961
- Object.entries(user.profile).forEach(([key, value]) => {
4962
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
4963
- resetData[key] = value;
4964
- }
4965
- });
4966
- }
4967
- setFormData(resetData);
4968
- }
4926
+ setName(user?.profile?.name || "");
4969
4927
  setIsEditing(false);
4970
- }, [user]);
4928
+ }, [user?.profile?.name]);
4971
4929
  const handleOverlayClick = useCallback(
4972
4930
  (e) => {
4973
4931
  if (e.target === e.currentTarget) {
@@ -4993,24 +4951,6 @@ function UserProfileModal({ onClose, onError }) {
4993
4951
  return null;
4994
4952
  }
4995
4953
  const initials = user.profile?.name ? user.profile.name.charAt(0).toUpperCase() : user.email.split("@")[0].slice(0, 2).toUpperCase();
4996
- const fields = [];
4997
- fields.push({ key: "email", value: user.email, readOnly: true });
4998
- fields.push({
4999
- key: "name",
5000
- value: isEditing ? formData.name || "" : user.profile?.name || "",
5001
- readOnly: false
5002
- });
5003
- if (user.profile) {
5004
- Object.entries(user.profile).forEach(([key, value]) => {
5005
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
5006
- fields.push({
5007
- key,
5008
- value: isEditing ? formData[key] ?? value : value,
5009
- readOnly: READ_ONLY_FIELDS.includes(key)
5010
- });
5011
- }
5012
- });
5013
- }
5014
4954
  return /* @__PURE__ */ jsx(ProfileModalOverlay, { onClick: handleOverlayClick, children: /* @__PURE__ */ jsxs(ProfileModalContainer, { onClick: (e) => e.stopPropagation(), children: [
5015
4955
  /* @__PURE__ */ jsxs(ProfileModalHeader, { children: [
5016
4956
  /* @__PURE__ */ jsx(ProfileModalTitle, { children: "Profile" }),
@@ -5025,18 +4965,25 @@ function UserProfileModal({ onClose, onError }) {
5025
4965
  onError: () => setImageError(true)
5026
4966
  }
5027
4967
  ) : initials }) }),
5028
- /* @__PURE__ */ jsx(ProfileFieldsContainer, { children: fields.map(({ key, value, readOnly }) => /* @__PURE__ */ jsxs(ProfileField, { children: [
5029
- /* @__PURE__ */ jsx(ProfileFieldLabel, { children: formatFieldLabel(key) }),
5030
- isEditing && !readOnly ? /* @__PURE__ */ jsx(
5031
- ProfileFieldInput,
5032
- {
5033
- type: "text",
5034
- value: formData[key] ?? value,
5035
- onChange: (e) => handleFieldChange(key, e.target.value),
5036
- disabled: isSaving
5037
- }
5038
- ) : /* @__PURE__ */ jsx(ProfileFieldValue, { children: value || "-" })
5039
- ] }, 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
+ ] })
5040
4987
  ] }),
5041
4988
  /* @__PURE__ */ jsx(ProfileModalFooter, { children: isEditing ? /* @__PURE__ */ jsxs(Fragment, { children: [
5042
4989
  /* @__PURE__ */ jsx(ProfileButton, { onClick: handleCancel, disabled: isSaving, children: "Cancel" }),