1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-21 13:47:39 +02:00
unleash.unleash/frontend/src/component/feedbackNew/useFeedback.tsx
Christopher Kolstad 53354224fc
chore: Bump biome and configure husky (#6589)
Upgrades biome to 1.6.1, and updates husky pre-commit hook.

Most changes here are making type imports explicit.
2024-03-18 13:58:05 +01:00

53 lines
1.2 KiB
TypeScript

import {
type IFeedbackCategory,
useUserSubmittedFeedback,
} from 'hooks/useSubmittedFeedback';
import {
FeedbackContext,
type FeedbackMode,
type IFeedbackContext,
} from './FeedbackContext';
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,
);
},
};
};