@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.
package/dist/index.js CHANGED
@@ -5444,32 +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"];
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
- name: user.profile?.name || ""
5462
- };
5463
- if (user.profile) {
5464
- Object.entries(user.profile).forEach(([key, value]) => {
5465
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
5466
- initialData[key] = value;
5467
- }
5468
- });
5469
- }
5470
- setFormData(initialData);
5454
+ if (user?.profile?.name) {
5455
+ setName(user.profile.name);
5471
5456
  }
5472
- }, [user]);
5457
+ }, [user?.profile?.name]);
5473
5458
  useEffect(() => {
5474
5459
  setImageError(false);
5475
5460
  const avatarUrl = user?.profile?.avatar_url;
@@ -5491,26 +5476,11 @@ function UserProfileModal({ onClose, onError }) {
5491
5476
  };
5492
5477
  void checkImageUrl();
5493
5478
  }, [user?.profile?.avatar_url]);
5494
- const handleFieldChange = useCallback((key, value) => {
5495
- setFormData((prev2) => ({
5496
- ...prev2,
5497
- [key]: value
5498
- }));
5499
- }, []);
5500
5479
  const handleSave = useCallback(async () => {
5501
5480
  if (!user) return;
5502
5481
  setIsSaving(true);
5503
5482
  try {
5504
- const { name, ...dynamicFields } = formData;
5505
- const updateData = {
5506
- profile: {
5507
- name
5508
- }
5509
- };
5510
- if (Object.keys(dynamicFields).length > 0) {
5511
- updateData.profile = dynamicFields;
5512
- }
5513
- const result = await updateUser(updateData);
5483
+ const result = await updateUser({ profile: { name } });
5514
5484
  if (result?.error) {
5515
5485
  onError?.(result.error);
5516
5486
  } else {
@@ -5521,23 +5491,11 @@ function UserProfileModal({ onClose, onError }) {
5521
5491
  } finally {
5522
5492
  setIsSaving(false);
5523
5493
  }
5524
- }, [user, formData, updateUser, onError]);
5494
+ }, [user, name, updateUser, onError]);
5525
5495
  const handleCancel = useCallback(() => {
5526
- if (user) {
5527
- const resetData = {
5528
- name: user.profile?.name || ""
5529
- };
5530
- if (user.profile) {
5531
- Object.entries(user.profile).forEach(([key, value]) => {
5532
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
5533
- resetData[key] = value;
5534
- }
5535
- });
5536
- }
5537
- setFormData(resetData);
5538
- }
5496
+ setName(user?.profile?.name || "");
5539
5497
  setIsEditing(false);
5540
- }, [user]);
5498
+ }, [user?.profile?.name]);
5541
5499
  const handleOverlayClick = useCallback(
5542
5500
  (e) => {
5543
5501
  if (e.target === e.currentTarget) {
@@ -5563,24 +5521,6 @@ function UserProfileModal({ onClose, onError }) {
5563
5521
  return null;
5564
5522
  }
5565
5523
  const initials = user.profile?.name ? user.profile.name.charAt(0).toUpperCase() : user.email.split("@")[0].slice(0, 2).toUpperCase();
5566
- const fields = [];
5567
- fields.push({ key: "email", value: user.email, readOnly: true });
5568
- fields.push({
5569
- key: "name",
5570
- value: isEditing ? formData.name || "" : user.profile?.name || "",
5571
- readOnly: false
5572
- });
5573
- if (user.profile) {
5574
- Object.entries(user.profile).forEach(([key, value]) => {
5575
- if (!HIDDEN_FIELDS.includes(key) && typeof value === "string") {
5576
- fields.push({
5577
- key,
5578
- value: isEditing ? formData[key] ?? value : value,
5579
- readOnly: READ_ONLY_FIELDS.includes(key)
5580
- });
5581
- }
5582
- });
5583
- }
5584
5524
  return /* @__PURE__ */ jsx(ProfileModalOverlay, { onClick: handleOverlayClick, children: /* @__PURE__ */ jsxs(ProfileModalContainer, { onClick: (e) => e.stopPropagation(), children: [
5585
5525
  /* @__PURE__ */ jsxs(ProfileModalHeader, { children: [
5586
5526
  /* @__PURE__ */ jsx(ProfileModalTitle, { children: "Profile" }),
@@ -5595,18 +5535,25 @@ function UserProfileModal({ onClose, onError }) {
5595
5535
  onError: () => setImageError(true)
5596
5536
  }
5597
5537
  ) : initials }) }),
5598
- /* @__PURE__ */ jsx(ProfileFieldsContainer, { children: fields.map(({ key, value, readOnly }) => /* @__PURE__ */ jsxs(ProfileField, { children: [
5599
- /* @__PURE__ */ jsx(ProfileFieldLabel, { children: formatFieldLabel(key) }),
5600
- isEditing && !readOnly ? /* @__PURE__ */ jsx(
5601
- ProfileFieldInput,
5602
- {
5603
- type: "text",
5604
- value: formData[key] ?? value,
5605
- onChange: (e) => handleFieldChange(key, e.target.value),
5606
- disabled: isSaving
5607
- }
5608
- ) : /* @__PURE__ */ jsx(ProfileFieldValue, { children: value || "-" })
5609
- ] }, 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
+ ] })
5610
5557
  ] }),
5611
5558
  /* @__PURE__ */ jsx(ProfileModalFooter, { children: isEditing ? /* @__PURE__ */ jsxs(Fragment, { children: [
5612
5559
  /* @__PURE__ */ jsx(ProfileButton, { onClick: handleCancel, disabled: isSaving, children: "Cancel" }),