mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import {useCallback, useEffect, useState} from 'react';
|
|
|
|
import {promptsCheck, promptsUpdate} from 'sentry/actionCreators/prompts';
|
|
import type {Organization} from 'sentry/types';
|
|
import {promptIsDismissed} from 'sentry/utils/promptIsDismissed';
|
|
import useApi from 'sentry/utils/useApi';
|
|
|
|
type Opts = {
|
|
feature: string;
|
|
organization: Organization;
|
|
projectId: string;
|
|
};
|
|
|
|
function usePromptCheck({feature, organization, projectId}: Opts) {
|
|
const api = useApi();
|
|
|
|
const [shouldShowPrompt, setShouldShow] = useState<boolean | null>(null);
|
|
|
|
useEffect(() => {
|
|
promptsCheck(api, {
|
|
organization,
|
|
projectId,
|
|
feature,
|
|
}).then(data => {
|
|
setShouldShow(!promptIsDismissed(data ?? {}, 30));
|
|
});
|
|
}, [api, feature, organization, projectId]);
|
|
|
|
const snoozePrompt = useCallback(async () => {
|
|
const data = {
|
|
projectId,
|
|
organization,
|
|
feature,
|
|
status: 'snoozed' as const,
|
|
};
|
|
await promptsUpdate(api, data);
|
|
setShouldShow(false);
|
|
}, [api, feature, organization, projectId]);
|
|
|
|
return {
|
|
shouldShowPrompt,
|
|
snoozePrompt,
|
|
};
|
|
}
|
|
|
|
export default usePromptCheck;
|