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: edit segment card changes #2081

Merged
merged 6 commits into from
Feb 23, 2024
Merged

fix: edit segment card changes #2081

merged 6 commits into from
Feb 23, 2024

Conversation

pandeymangg
Copy link
Contributor

What does this PR do?

Fixes multiple issues with the edit segment card:

  1. Clicking on edit segment now shows a new save changes button that saves the segment changes, and the survey save button is disabled. This happens only if the segment is not private.
  2. There is now an option to reset the filters and go back to an inline segment in a survey.
  3. The load segment modal now also shows the currently applied segment in a disabled state.
  4. Clicking on save changes will take the user back to a similar state as clicking on cancel (segment editor will be open in view only mode).

Fixes # (issue)

Screen.Recording.2024-02-15.at.12.57.49.PM.mov

How should this be tested?

  • Open the survey editor, load a segment in it
  • there should be these fixes applied for that segment

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 15, 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 15, 2024 3:01pm
formbricks-com ⬜️ Ignored (Inspect) Visit Preview Feb 15, 2024 3:01pm

Copy link
Contributor

github-actions bot commented Feb 15, 2024

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

Copy link
Contributor

apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/edit/actions.ts

Consider abstracting the authorization check into a separate function. This will improve code readability and maintainability.
Create Issue
See the diff
Checkout the fix

    async function checkUserAccess(session, surveyId) {
      if (!session) throw new AuthorizationError("Not authorized");
      const environmentAccess = await canUserAccessSurvey(session.user.id, surveyId);
      if (!environmentAccess) throw new AuthorizationError("Not authorized");
    }
git fetch origin && git checkout -b ReviewBot/Impro-1s4b8ql origin/ReviewBot/Impro-1s4b8ql

packages/ee/advancedTargeting/lib/actions.ts

Consider abstracting the authorization check into a separate function. This will improve code readability and maintainability.
Create Issue
See the diff
Checkout the fix

    async function checkUserAccess(session, surveyId) {
      if (!session) throw new AuthorizationError("Not authorized");
      const environmentAccess = await canUserAccessSurvey(session.user.id, surveyId);
      if (!environmentAccess) throw new AuthorizationError("Not authorized");
    }
git fetch origin && git checkout -b ReviewBot/Impro-n89ixad origin/ReviewBot/Impro-n89ixad

packages/ee/advancedTargeting/components/AdvancedTargetingCard.tsx

Consider breaking down the large component into smaller, more manageable components. This will make the code easier to read and maintain.
Create Issue
See the diff
Checkout the fix

    // Break down the large component into smaller components
    const SegmentEditorComponent = ({...props}) => {
      // Segment editor related code
    }

    const FilterModalComponent = ({...props}) => {
      // Filter modal related code
    }

    const SegmentDetailComponent = ({...props}) => {
      // Segment detail related code
    }

    // Use the smaller components in the main component
    const AdvancedTargetingCard = ({...props}) => {
      return (
        <>
          <SegmentEditorComponent {...props} />
          <FilterModalComponent {...props} />
          <SegmentDetailComponent {...props} />
        </>
      )
    }
git fetch origin && git checkout -b ReviewBot/The-c-4utjt93 origin/ReviewBot/The-c-4utjt93

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

    // Use useCallback for handleSaveSegment
    const handleSaveSegment = useCallback(async (data: TSegmentUpdateInput) => {
      try {
        if (!segment) throw new Error("Invalid segment");
        await updateSegmentAction(environmentId, segment?.id, data);
        toast.success("Segment saved successfully");

        setIsSegmentEditorOpen(false);
        setSegmentEditorViewOnly(true);
      } catch (err: any) {
        toast.error(err.message ?? "Error Saving Segment");
      }
    }, [environmentId, segment]);
git fetch origin && git checkout -b ReviewBot/The-c-nm9pka9 origin/ReviewBot/The-c-nm9pka9

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 thanks for the PR 😊 Works great! 👍
Can we also solve this by showing a field validation message instead of disabling the save button (I think we are doing this in other places that way) or also changing the green check mark as it might be hard for a user to find where the problem is if they have e.g. collapsed the card?
https://files.slack.com/files-pri/T051W9BL93J-F06JZ61RK0T/screenshot_2024-02-15_at_13.48.13.png

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 thanks for making the changes 😊💪🚀

@mattinannt mattinannt added this pull request to the merge queue Feb 23, 2024
Merged via the queue into main with commit 6111e02 Feb 23, 2024
13 checks passed
@mattinannt mattinannt deleted the fix/edit-segment-card branch February 23, 2024 10:24
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.

2 participants