1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-24 20:06:55 +01:00
unleash.unleash/frontend/src/component/feedbackNew/useFeedback.tsx
Gastón Fournier abe160eb7d
feat: Unleash v7 ESM migration (#9877)
We're migrating to ESM, which will allow us to import the latest
versions of our dependencies.

Co-Authored-By: Christopher Kolstad <chriswk@getunleash.io>
2025-05-14 09:47:12 +02:00

53 lines
1.2 KiB
TypeScript

import {
type IFeedbackCategory,
useUserSubmittedFeedback,
} from 'hooks/useSubmittedFeedback';
import {
FeedbackContext,
type FeedbackMode,
type IFeedbackContext,
} from './FeedbackContext.ts';
import { useContext } from 'react';
type OpenFeedbackParams = {
title: string;
positiveLabel: string;
areasForImprovementsLabel: string;
};
export const useFeedbackContext = (): IFeedbackContext => {
const context = useContext(FeedbackContext);
if (!context) {
throw new Error(
'useFeedbackContext must be used within a FeedbackProvider',
);
}
return context;
};
export const useFeedback = (
feedbackCategory: IFeedbackCategory,
mode: FeedbackMode,
variant: string = '',
) => {
const context = useFeedbackContext();
const { hasSubmittedFeedback } = useUserSubmittedFeedback(feedbackCategory);
return {
...context,
hasSubmittedFeedback,
openFeedback: (parameters: OpenFeedbackParams) => {
context.openFeedback(
{
...parameters,
category: feedbackCategory,
},
mode,
variant,
);
},
};
};