@redotech/redo-hydrogen
Version:
Utilities to enable and disable Redo coverage on Hydrogen stores
102 lines (93 loc) • 3.82 kB
TypeScript
import { CartReturn, OptimisticCart } from '@shopify/hydrogen';
import { ReactNode, DependencyList } from 'react';
import { CartWithActionsDocs } from '@shopify/hydrogen-react/dist/types/cart-types';
import { ProductVariant } from '@shopify/hydrogen-react/storefront-api-types';
import * as react_jsx_runtime from 'react/jsx-runtime';
type CartProductVariantFragment = Omit<ProductVariant, "components" | "metafields" | "quantityPriceBreaks" | "quantityRule" | "requiresComponents" | "requiresShipping" | "storeAvailability" | "taxable" | "weightUnit">;
type CartAttributeKey = string;
interface RedoCoverageClient {
enable(): Promise<boolean>;
disable(): Promise<boolean>;
get loading(): boolean;
get enabled(): boolean;
get eligible(): boolean;
get price(): number | undefined;
get storeId(): string | undefined;
get cart(): CartReturn | CartWithActionsDocs | OptimisticCart | undefined;
get cartProduct(): CartProductVariantFragment | undefined;
get cartAttribute(): CartAttributeKey | undefined;
get errors(): RedoError[] | undefined;
}
type CartInfoToEnable = {
productId: string;
variantId: string;
cartAttribute: CartAttributeKey;
selectedVariant: CartProductVariantFragment;
};
type RedoContextValue = {
enabled: boolean;
loading: boolean;
storeId?: string;
cartInfoToEnable?: CartInfoToEnable;
cart?: CartReturn | CartWithActionsDocs | OptimisticCart;
errors?: RedoError[];
};
declare enum RedoErrorType {
ApiBadRequest = "API_BAD_REQUEST",
ApiServerError = "API_SERVER_ERROR",
ApiUnknownError = "API_UNKNOWN_ERROR"
}
type RedoError = {
type: RedoErrorType;
message: string;
context: Record<string, unknown>;
};
declare const RedoProvider: ({ cart, storeId, children, }: {
cart: CartReturn | CartWithActionsDocs | OptimisticCart;
storeId: string;
children: ReactNode;
}) => ReactNode;
declare const useRedoCoverageClient: () => RedoCoverageClient;
declare const RedoCheckoutButtons: (props: {
children?: ReactNode;
onClick?: (enabled: boolean) => void;
}) => react_jsx_runtime.JSX.Element;
declare const REDO_REQUIRED_HOSTNAMES: string[];
interface Loader<T> {
(abort: AbortSignal): Promise<T>;
}
interface LoadState<T> {
error?: unknown;
pending: boolean;
value?: T;
}
declare function useLoad<T>(fn: Loader<T>, deps: DependencyList): LoadState<T>;
interface RedoInfoModalProps {
showInfoIcon?: boolean;
onInfoClick?: () => void;
infoCardImageUrl?: string;
infoModalLogoUrl?: string;
infoModalImageUrl?: string;
infoModalContent?: ReactNode;
}
declare const RedoInfoCard: ({ showInfoIcon, onInfoClick, infoCardImageUrl, infoModalLogoUrl, infoModalImageUrl, infoModalContent, }: RedoInfoModalProps) => react_jsx_runtime.JSX.Element;
/**
* React hook to disable add-to-cart buttons when a Purple Dot preorder element is present.
* Watches for DOM changes and automatically disables/enables buttons based on the presence
* of the <purple-dot-learn-more> element.
*
* @param disablePreorderButtons - When true, enables the preorder button disabling logic.
* When false, the hook does nothing.
*
* Usage:
* ```tsx
* function ProductPage() {
* const isShopOnSiteActive = true; // your condition here
* useDisablePurpleDotPreorder(isShopOnSiteActive);
* return <div>...</div>;
* }
* ```
*/
declare function useDisablePurpleDotPreorder(disablePreorderButtons: boolean): void;
export { REDO_REQUIRED_HOSTNAMES, RedoCheckoutButtons, RedoErrorType, RedoInfoCard, RedoProvider, useDisablePurpleDotPreorder, useLoad, useRedoCoverageClient };
export type { CartAttributeKey, CartInfoToEnable, CartProductVariantFragment, LoadState, Loader, RedoContextValue, RedoCoverageClient, RedoError };