@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/index.js CHANGED
@@ -5444,30 +5444,17 @@ var ProfileSpinner = styled.div`
5444
5444
  }
5445
5445
  }
5446
5446
  `;
5447
- var READ_ONLY_FIELDS = ["id", "email", "avatar_url", "created_at", "updated_at"];
5448
- var HIDDEN_FIELDS = ["id", "avatar_url"];
5449
- function formatFieldLabel(key) {
5450
- return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase();
5451
- }
5452
5447
  function UserProfileModal({ onClose, onError }) {
5453
5448
  const { user, updateUser, isLoaded } = useInsforge();
5454
5449
  const [isEditing, setIsEditing] = useState(false);
5455
5450
  const [isSaving, setIsSaving] = useState(false);
5456
5451
  const [imageError, setImageError] = useState(false);
5457
- const [formData, setFormData] = useState({});
5452
+ const [name, setName] = useState("");
5458
5453
  useEffect(() => {
5459
- if (user) {
5460
- const initialData = {};
5461
- if (user.profile) {
5462
- Object.entries(user.profile).forEach(([key, value]) => {
5463
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
5464
- initialData[key] = value;
5465
- }
5466
- });
5467
- }
5468
- setFormData(initialData);
5454
+ if (user?.profile?.name) {
5455
+ setName(user.profile.name);
5469
5456
  }
5470
- }, [user]);
5457
+ }, [user?.profile?.name]);
5471
5458
  useEffect(() => {
5472
5459
  setImageError(false);
5473
5460
  const avatarUrl = user?.profile?.avatar_url;
@@ -5489,26 +5476,11 @@ function UserProfileModal({ onClose, onError }) {
5489
5476
  };
5490
5477
  void checkImageUrl();
5491
5478
  }, [user?.profile?.avatar_url]);
5492
- const handleFieldChange = useCallback((key, value) => {
5493
- setFormData((prev2) => ({
5494
- ...prev2,
5495
- [key]: value
5496
- }));
5497
- }, []);
5498
5479
  const handleSave = useCallback(async () => {
5499
5480
  if (!user) return;
5500
5481
  setIsSaving(true);
5501
5482
  try {
5502
- const { name, ...dynamicFields } = formData;
5503
- const updateData = {
5504
- profile: {
5505
- name
5506
- }
5507
- };
5508
- if (Object.keys(dynamicFields).length > 0) {
5509
- updateData.profile = dynamicFields;
5510
- }
5511
- const result = await updateUser(updateData);
5483
+ const result = await updateUser({ profile: { name } });
5512
5484
  if (result?.error) {
5513
5485
  onError?.(result.error);
5514
5486
  } else {
@@ -5519,23 +5491,11 @@ function UserProfileModal({ onClose, onError }) {
5519
5491
  } finally {
5520
5492
  setIsSaving(false);
5521
5493
  }
5522
- }, [user, formData, updateUser, onError]);
5494
+ }, [user, name, updateUser, onError]);
5523
5495
  const handleCancel = useCallback(() => {
5524
- if (user) {
5525
- const resetData = {
5526
- name: user.profile?.name || ""
5527
- };
5528
- if (user.profile) {
5529
- Object.entries(user.profile).forEach(([key, value]) => {
5530
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
5531
- resetData[key] = value;
5532
- }
5533
- });
5534
- }
5535
- setFormData(resetData);
5536
- }
5496
+ setName(user?.profile?.name || "");
5537
5497
  setIsEditing(false);
5538
- }, [user]);
5498
+ }, [user?.profile?.name]);
5539
5499
  const handleOverlayClick = useCallback(
5540
5500
  (e) => {
5541
5501
  if (e.target === e.currentTarget) {
@@ -5561,24 +5521,6 @@ function UserProfileModal({ onClose, onError }) {
5561
5521
  return null;
5562
5522
  }
5563
5523
  const initials = user.profile?.name ? user.profile.name.charAt(0).toUpperCase() : user.email.split("@")[0].slice(0, 2).toUpperCase();
5564
- const fields = [];
5565
- fields.push({ key: "email", value: user.email, readOnly: true });
5566
- fields.push({
5567
- key: "name",
5568
- value: isEditing ? formData.name || "" : user.profile?.name || "",
5569
- readOnly: false
5570
- });
5571
- if (user.profile) {
5572
- Object.entries(user.profile).forEach(([key, value]) => {
5573
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
5574
- fields.push({
5575
- key,
5576
- value: isEditing ? formData[key] ?? value : value,
5577
- readOnly: READ_ONLY_FIELDS.includes(key)
5578
- });
5579
- }
5580
- });
5581
- }
5582
5524
  return /* @__PURE__ */ jsx(ProfileModalOverlay, { onClick: handleOverlayClick, children: /* @__PURE__ */ jsxs(ProfileModalContainer, { onClick: (e) => e.stopPropagation(), children: [
5583
5525
  /* @__PURE__ */ jsxs(ProfileModalHeader, { children: [
5584
5526
  /* @__PURE__ */ jsx(ProfileModalTitle, { children: "Profile" }),
@@ -5593,18 +5535,25 @@ function UserProfileModal({ onClose, onError }) {
5593
5535
  onError: () => setImageError(true)
5594
5536
  }
5595
5537
  ) : initials }) }),
5596
- /* @__PURE__ */ jsx(ProfileFieldsContainer, { children: fields.map(({ key, value, readOnly }) => /* @__PURE__ */ jsxs(ProfileField, { children: [
5597
- /* @__PURE__ */ jsx(ProfileFieldLabel, { children: formatFieldLabel(key) }),
5598
- isEditing && !readOnly ? /* @__PURE__ */ jsx(
5599
- ProfileFieldInput,
5600
- {
5601
- type: "text",
5602
- value: formData[key] ?? value,
5603
- onChange: (e) => handleFieldChange(key, e.target.value),
5604
- disabled: isSaving
5605
- }
5606
- ) : /* @__PURE__ */ jsx(ProfileFieldValue, { children: value || "-" })
5607
- ] }, key)) })
5538
+ /* @__PURE__ */ jsxs(ProfileFieldsContainer, { children: [
5539
+ /* @__PURE__ */ jsxs(ProfileField, { children: [
5540
+ /* @__PURE__ */ jsx(ProfileFieldLabel, { children: "email" }),
5541
+ /* @__PURE__ */ jsx(ProfileFieldValue, { children: user.email })
5542
+ ] }),
5543
+ /* @__PURE__ */ jsxs(ProfileField, { children: [
5544
+ /* @__PURE__ */ jsx(ProfileFieldLabel, { children: "name" }),
5545
+ isEditing ? /* @__PURE__ */ jsx(
5546
+ ProfileFieldInput,
5547
+ {
5548
+ type: "text",
5549
+ value: name,
5550
+ onChange: (e) => setName(e.target.value),
5551
+ disabled: isSaving,
5552
+ placeholder: "Enter your name"
5553
+ }
5554
+ ) : /* @__PURE__ */ jsx(ProfileFieldValue, { children: user.profile?.name || "-" })
5555
+ ] })
5556
+ ] })
5608
5557
  ] }),
5609
5558
  /* @__PURE__ */ jsx(ProfileModalFooter, { children: isEditing ? /* @__PURE__ */ jsxs(Fragment, { children: [
5610
5559
  /* @__PURE__ */ jsx(ProfileButton, { onClick: handleCancel, disabled: isSaving, children: "Cancel" }),