Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: segments modals #2070

Merged
merged 3 commits into from
Feb 14, 2024
Merged

fix: segments modals #2070

merged 3 commits into from
Feb 14, 2024

Conversation

pandeymangg
Copy link
Contributor

What does this PR do?

Fixes the modals on the segments page showing encrypted error messages on production. The segment edit and create modals now have the save button disabled if a segment has no title or if the filters are wrong.
Fixes # (issue)

Screenshot 2024-02-14 at 10 55 53 AM
Screenshot 2024-02-14 at 10 56 14 AM

How should this be tested?

  • Go the segments page from the navbar (people and segments)
  • Create a segment / edit an existing one

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Copy link

vercel bot commented Feb 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Visit Preview Feb 14, 2024 9:34am
formbricks-com ⬜️ Ignored (Inspect) Visit Preview Feb 14, 2024 9:34am

Copy link
Contributor

github-actions bot commented Feb 14, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

apps/web/app/(app)/environments/[environmentId]/(peopleAndSegments)/segments/components/BasicSegmentSettings.tsx

Consider using a more descriptive variable name than err for error handling. This will improve code readability and maintainability.
Create Issue
See the diff
Checkout the fix

    } catch (error: any) {
      toast.error("Something went wrong. Please try again.");
    }
git fetch origin && git checkout -b ReviewBot/The-c-qg6kie8 origin/ReviewBot/The-c-qg6kie8

Consider using useCallback for the handleAddFilterInGroup function. This will prevent unnecessary re-renders and improve performance.
Create Issue
See the diff
Checkout the fix

    const handleAddFilterInGroup = useCallback((filter: TBaseFilter) => {
      const updatedSegment = structuredClone(segment);
      if (updatedSegment?.filters?.length === 0) {
        updatedSegment.filters.push({
          ...filter,
          connector: null,
        });
      } else {
        updatedSegment?.filters.push(filter);
      }

      setSegment(updatedSegment);
    }, [segment]);
git fetch origin && git checkout -b ReviewBot/There-cqefd93 origin/ReviewBot/There-cqefd93

Consider using useCallback for the handleUpdateSegment function. This will prevent unnecessary re-renders and improve performance.
Create Issue
See the diff
Checkout the fix

    const handleUpdateSegment = useCallback(async () => {
      if (!segment.title) {
        toast.error("Title is required.");
        return;
      }

      try {
        setIsUpdatingSegment(true);
        await updateBasicSegmentAction(segment.environmentId, segment.id, {
          title: segment.title,
          description: segment.description ?? "",
          isPrivate: segment.isPrivate,
          filters: segment.filters,
        });

        setIsUpdatingSegment(false);
        toast.success("Segment updated successfully!");
      } catch (error: any) {
        const parsedFilters = ZSegmentFilters.safeParse(segment.filters);
        if (!parsedFilters.success) {
          toast.error("Invalid filters. Please check the filters and try again.");
        } else {
          toast.error("Something went wrong. Please try again.");
        }
        setIsUpdatingSegment(false);
        return;
      }

      setIsUpdatingSegment(false);
      handleResetState();
      router.refresh();
    }, [segment, router]);
git fetch origin && git checkout -b ReviewBot/There-8ns03sy origin/ReviewBot/There-8ns03sy

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandeymangg 💪 thank you for the modal fixes 😊💪🚀

@mattinannt mattinannt added this pull request to the merge queue Feb 14, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 14, 2024
@mattinannt mattinannt added this pull request to the merge queue Feb 14, 2024
Merged via the queue into main with commit e6fe027 Feb 14, 2024
13 checks passed
@mattinannt mattinannt deleted the hotfix/segment-page-err branch February 14, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants