import {RequestScopesConsentResponse} from '@shopify/shop-minis-platform/actions' import {useHandleAction} from '../../internal/useHandleAction' import {useShopActions} from '../../internal/useShopActions' export interface UseRequestScopesConsentReturns { /** * Programmatically show the consent sheet for the Mini's required scopes. * * The sheet will show even if the user previously rejected it in the same * session. Use this to build retry UX (e.g., a "Connect account" button). * * Resolves with `{granted: boolean}`. Rejects with `'request_blocked'` * if the request can't be served right now — either another consent or * permission sheet is already showing, or the Mini's scope state hasn't * finished loading yet. * * Call `refetch()` on `useCheckScopesConsent` after resolution to get the * updated scope status. */ requestScopesConsent: () => Promise } export const useRequestScopesConsent = (): UseRequestScopesConsentReturns => { const {requestScopesConsent} = useShopActions() return { requestScopesConsent: useHandleAction(requestScopesConsent), } } /** * Returns a function to programmatically show the consent sheet. Use this to * build re-consent UX after the user has previously rejected, or when partial * scope grants are detected via `useCheckScopesConsent`. * @publicDocs */ export type UseRequestScopesConsentGeneratedType = () => UseRequestScopesConsentReturns