5180 fichiers 38.5 Mo 0 téléchargements 224 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / hooks / catalog / useGiftConfiguration.ts
useGiftConfiguration.ts 1.4 Ko Télécharger le fichier
import { GetGiftWrappingConfigurationComposer, GiftWrappingConfigurationEvent } from '@octane/renderer';
import { UseQueryResult } from '@tanstack/react-query';
import { GiftWrappingConfiguration } from '../../api';
import { useOctaneQuery } from '../../api/octane-query';

/**
 * Wraps the GetGiftWrappingConfigurationComposer / GiftWrappingConfigurationEvent
 * request-response pair as a TanStack query. The configuration is
 * session-stable (box types, ribbon types, colour palette) so the data
 * is cached with `staleTime: Infinity` — the server is asked at most
 * once per session.
 *
 * Replaces the previous pattern in useCatalog where the composer was
 * dispatched eagerly inside an `isVisible` effect and the result was
 * stored in `catalogOptions.giftConfiguration`. Consumers now read the
 * query directly and benefit from the standard TanStack loading/error
 * states.
 */
export const useGiftConfiguration = (options: { enabled?: boolean } = {}): UseQueryResult<GiftWrappingConfiguration> =>
    useOctaneQuery<GiftWrappingConfigurationEvent, GiftWrappingConfiguration>({
        key: ['octane', 'catalog', 'giftConfiguration'],
        request: () => new GetGiftWrappingConfigurationComposer(),
        parser: GiftWrappingConfigurationEvent,
        select: (event) => new GiftWrappingConfiguration(event.getParser()),
        enabled: options.enabled,
        staleTime: Infinity
    });
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser