1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: prompt for feedback after second flag created (#8467)

This commit is contained in:
Tymoteusz Czech 2024-10-17 10:49:17 +02:00 committed by GitHub
parent 2ec575b85c
commit 793221524c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 10 deletions

View File

@ -2,20 +2,13 @@ import { formatUnknownError } from 'utils/formatUnknownError';
import useToast from 'hooks/useToast';
import FormTemplate from 'component/common/FormTemplate/FormTemplate';
import { CREATE_FEATURE } from 'component/providers/AccessProvider/permissions';
import {
type ReactNode,
useState,
useContext,
type FormEvent,
useMemo,
} from 'react';
import { type ReactNode, useState, type FormEvent, useMemo } from 'react';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { useNavigate } from 'react-router-dom';
import { Dialog, styled } from '@mui/material';
import useProjects from 'hooks/api/getters/useProjects/useProjects';
import { Limit } from 'component/common/Limit/Limit';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import UIContext from 'contexts/UIContext';
import useFeatureForm from 'component/feature/hooks/useFeatureForm';
import useFeatureApi from 'hooks/api/actions/useFeatureApi/useFeatureApi';
import FlagIcon from '@mui/icons-material/Flag';
@ -36,6 +29,7 @@ import { MultiSelectConfigButton } from 'component/common/DialogFormTemplate/Con
import type { ITag } from 'interfaces/tags';
import { ToggleConfigButton } from 'component/common/DialogFormTemplate/ConfigButtons/ToggleConfigButton';
import { useFlagLimits } from './useFlagLimits';
import { useFeatureCreatedFeedback } from './hooks/useFeatureCreatedFeedback';
interface ICreateFeatureDialogProps {
open: boolean;
@ -104,9 +98,9 @@ const CreateFeatureDialogContent = ({
onSuccess,
}: ICreateFeatureDialogProps) => {
const { setToastData, setToastApiError } = useToast();
const { setShowFeedback } = useContext(UIContext);
const { uiConfig, isOss } = useUiConfig();
const navigate = useNavigate();
const openFeatureCreatedFeedback = useFeatureCreatedFeedback();
const {
type,
@ -177,7 +171,7 @@ const CreateFeatureDialogContent = ({
});
onClose();
onSuccess?.();
setShowFeedback(true);
openFeatureCreatedFeedback();
} catch (error: unknown) {
setToastApiError(formatUnknownError(error));
}

View File

@ -0,0 +1,21 @@
import { useCallback, useContext } from 'react';
import UIContext from 'contexts/UIContext';
import { createLocalStorage } from 'utils/createLocalStorage';
export const useFeatureCreatedFeedback = () => {
const { setShowFeedback } = useContext(UIContext);
return useCallback(() => {
const { value, setValue } = createLocalStorage<string>(
'flagsCreated',
'0',
);
const flagsCount = Number.parseInt(value) + 1;
setValue(`${flagsCount}`);
if (flagsCount > 1) {
setShowFeedback(true);
}
}, [setShowFeedback]);
};