Skip to content

Commit 5c278dc

Browse files
committed
👔 Move acknowledgement mutation into it's own custom hook
1 parent d6daf14 commit 5c278dc

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
@@ -23,13 +23,36 @@ export const ASK_SEER_CONSENT_ITEM_KEY = 'ask_seer_consent';
2323
const setupCheckQueryKey = (orgSlug: string) =>
2424
`/organizations/${orgSlug}/seer/setup-check/`;
2525

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

3457
useEffect(() => {
3558
const link = linkRef.current;
@@ -47,22 +70,6 @@ function AskSeerConsentOption<T>({state}: {state: ComboBoxState<T>}) {
4770
};
4871
}, []);
4972

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

8693
return (

0 commit comments

Comments
 (0)