Skip to content

Commit fbfcd52

Browse files
committed
👔 Move acknowledgement mutation into it's own custom hook
1 parent b80b69e commit fbfcd52

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

static/app/components/searchQueryBuilder/askSeer.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,36 @@ export const ASK_SEER_CONSENT_ITEM_KEY = 'ask_seer_consent';
2424
const setupCheckQueryKey = (orgSlug: string) =>
2525
`/organizations/${orgSlug}/seer/setup-check/`;
2626

27-
function AskSeerConsentOption<T>({state}: {state: ComboBoxState<T>}) {
27+
export function useSeerAcknowledgeMutation() {
2828
const api = useApi();
2929
const queryClient = useQueryClient();
3030
const organization = useOrganization();
31+
32+
const {mutate} = useMutation({
33+
mutationKey: [setupCheckQueryKey(organization.slug)],
34+
mutationFn: () => {
35+
return promptsUpdate(api, {
36+
organization,
37+
feature: 'seer_autofix_setup_acknowledged',
38+
status: 'dismissed',
39+
});
40+
},
41+
onSuccess: () => {
42+
queryClient.invalidateQueries({
43+
queryKey: [setupCheckQueryKey(organization.slug)],
44+
});
45+
},
46+
});
47+
48+
return {mutate};
49+
}
50+
51+
function AskSeerConsentOption<T>({state}: {state: ComboBoxState<T>}) {
52+
const organization = useOrganization();
3153
const itemRef = useRef<HTMLDivElement>(null);
3254
const linkRef = useRef<HTMLAnchorElement>(null);
3355
const [optionDisableOverride, setOptionDisableOverride] = useState(false);
56+
const {mutate: seerAcknowledgeMutate} = useSeerAcknowledgeMutation();
3457

3558
useEffect(() => {
3659
const link = linkRef.current;
@@ -48,22 +71,6 @@ function AskSeerConsentOption<T>({state}: {state: ComboBoxState<T>}) {
4871
};
4972
}, []);
5073

51-
const seerAcknowledgeMutation = useMutation({
52-
mutationKey: [setupCheckQueryKey(organization.slug)],
53-
mutationFn: () => {
54-
return promptsUpdate(api, {
55-
organization,
56-
feature: 'seer_autofix_setup_acknowledged',
57-
status: 'dismissed',
58-
});
59-
},
60-
onSuccess: () => {
61-
queryClient.invalidateQueries({
62-
queryKey: [setupCheckQueryKey(organization.slug)],
63-
});
64-
},
65-
});
66-
6774
const {optionProps, labelProps, isFocused, isPressed} = useOption(
6875
{
6976
key: ASK_SEER_CONSENT_ITEM_KEY,
@@ -81,7 +88,7 @@ function AskSeerConsentOption<T>({state}: {state: ComboBoxState<T>}) {
8188
organization,
8289
action: 'consent_accepted',
8390
});
84-
seerAcknowledgeMutation.mutate();
91+
seerAcknowledgeMutate();
8592
};
8693

8794
return (

0 commit comments

Comments
 (0)