|
| 1 | +import { i18n, TR } from "@/localization/translate.service"; |
| 2 | +import { sendEmail } from "@/utils/email"; |
| 3 | +import { SUPPORT_MAIL } from "@/utils/general.constants"; |
| 4 | +import * as Sentry from "@sentry/react-native"; |
| 5 | +import * as QuickActions from "expo-quick-actions"; |
| 6 | +import { useQuickActionCallback } from "expo-quick-actions/hooks"; |
| 7 | +import { useEffect } from "react"; |
| 8 | +import { Platform } from "react-native"; |
| 9 | + |
| 10 | +enum EQuickAction { |
| 11 | + DO_NOT_DELETE = "do_not_delete", |
| 12 | +} |
| 13 | + |
| 14 | +export const useQuickAction = () => { |
| 15 | + useEffect(() => { |
| 16 | + QuickActions.isSupported() |
| 17 | + .then((isSupported) => { |
| 18 | + if (isSupported) { |
| 19 | + QuickActions.setItems([ |
| 20 | + { |
| 21 | + title: i18n.t(TR.quickActionDontDeleteMeTitle), |
| 22 | + subtitle: i18n.t( |
| 23 | + TR.quickActionDontDeleteMeSubTitle, |
| 24 | + ), |
| 25 | + icon: |
| 26 | + Platform.OS === "ios" |
| 27 | + ? "symbol:questionmark.circle" |
| 28 | + : "help_icon", |
| 29 | + id: EQuickAction.DO_NOT_DELETE, |
| 30 | + // params: { href: `/${EQuickAction.DO_NOT_DELETE}` }, // @dev href param requires useQuickActionRouting |
| 31 | + }, |
| 32 | + ]); |
| 33 | + } |
| 34 | + }) |
| 35 | + .catch((err) => { |
| 36 | + Sentry.captureException(err, { |
| 37 | + tags: { |
| 38 | + quickActionsSupported: |
| 39 | + "notAbleToCheckQuickActionSupport", |
| 40 | + }, |
| 41 | + }); |
| 42 | + }); |
| 43 | + }, []); |
| 44 | + // useQuickActionRouting(); // @dev only works with expo router |
| 45 | + |
| 46 | + useQuickActionCallback((action) => { |
| 47 | + switch (action.id) { |
| 48 | + case EQuickAction.DO_NOT_DELETE: |
| 49 | + // TODO: Show feedback modal, explainer, etc., for now just email |
| 50 | + sendEmail( |
| 51 | + SUPPORT_MAIL, |
| 52 | + i18n.t(TR.quickActionDontDeleteMeEmailSubject), |
| 53 | + i18n.t(TR.quickActionDontDeleteMeEmailBody), |
| 54 | + ); |
| 55 | + break; |
| 56 | + } |
| 57 | + }); |
| 58 | +}; |
0 commit comments