Broadleaf Microservices
  • v1.0.0-latest-prod

Quote React Hooks

useConvertExpiredToCart

Hook to use to make a request to convert an expired Quote into a regular Cart. This hook provides a callback method and an API error if any.

Props

An object containing the following:

  • quoteClient: The client used to make the request.

    • This comes from the @broadleaf/commerce-cart SDK.

  • setCart: The callback needed to handle setting the app’s cart state.

    • (cart: Cart | null) ⇒ void

Response

An object containing the following:

  • convertToCart: Callback function to send the request.

    • Takes 2 arguments

      • selectedQuote: The quote to convert

      • type: The Cart#type. Default is STANDARD.

useConfigContext

Hook to use to access the ConfigContext.

Props

None

Response

useDelayHover

Hook to use to delay a hover action. For example, keeping a dropdown open for a second after the user’s cursor is no longer hovered over it. Produces a handleMouseEnter and a handleMouseLeave event handler.

Props

An object containing the following:

  • value: Whether the hover is active.

    • boolean

  • setValue: Function to set the hover active state.

    • (value: boolean, event?: MouseEvent<T>) ⇒ void;

  • openDelay: The number of milliseconds to wait before setting the active state to true.

    • number

    • Default is 500

  • closeDelay: The number of milliseconds to wait before setting the active state to false.

    • number

    • Default is 500

  • includeEvent: Whether to pass the JavaScript event object to setValue in addition to true or false.

    • boolean

    • Default is false

Response

An object containing the following:

  • handleMouseEnter: Mouse-enter callback handler.

    • Takes the JavaScript event object.

  • handleMouseLeave: Mouse-leave callback handler.

    • Takes the JavaScript event object.

useFetchQuotes

Hook to use to make a request to fetch a list of quotes.

Props

An object containing the following:

  • quoteClient: Client for making requests. From @broadleaf/commerce-cart.

  • searchParam: Query param to include in the request in the cq. Filters by Quote name.

    • string

    • Not required.

  • sort: Sort param to include, e.g., name,asc

    • string

  • fromDate: Date to use as the starting point for filtering quotes by create date.

    • string

  • toDate: Date to use as the ending point for filtering quotes by create date.

    • string

  • pagination: Additional pagination props

Response

An object containing the following:

  • isFetching: Whether the request is in progress.

    • boolean

  • error: Any error produced by the request.

    • ApiError | unknown

  • carts: The page of quote type carts if no error was encountered.

    • Page<Cart>

  • refetch: Method to resend the request.

    • () ⇒ Promise<void>

useFetchChangeHistory

Hook to use to make a request to fetch a list of CartActionAudits for a quote.

Props

An object containing the following:

  • quoteClient: The client used to make the request.

    • This comes from the @broadleaf/commerce-cart SDK.

  • quoteId: Id of the parent quote.

    • string

Response

An object containing the following:

  • fetchChangeHistory: Function to make the request.

    • () ⇒ Promise<void>

  • changeHistory: Page of audits.

  • error: Any error produced by the request.

    • ApiError | unknown

useFetchNotes

Hook to use to make a request to fetch a list of notes for a quote.

Props

An object containing the following:

  • quoteItemId: Optional. Id of the parent quote item.

  • quoteClient: The client used to make the request.

    • This comes from the @broadleaf/commerce-cart SDK.

  • quoteId: Id of the parent quote.

    • string

Response

An object containing the following:

  • fetchNotes: Function to make the request.

    • () ⇒ Promise<void>

  • notes: Page of notes.

  • error: Any error produced by the request.

    • ApiError | unknown

useFetchQuoteById

Hook to use to make a request to fetch a quote by id.

Props

An object containing the following:

  • quoteClient: The client used to make the request.

    • This comes from the @broadleaf/commerce-cart SDK.

  • quoteId: Id of the parent quote.

    • string

Response

An object containing the following:

  • isFetching: Whether the request is in progress.

    • boolean

  • error: Any error produced by the request.

    • ApiError | unknown

  • quote: The quote if no error was encountered.

    • Cart

  • refetch: Method to resend the request.

    • () ⇒ Promise<void>

useFormatDate

Hook that wraps react-intl’s useIntl() and returns only the formatDate function.

useFormatMessage

Hook that wraps react-intl’s useIntl() and returns only the formatMessage function.

useFormatTime

Hook that wraps react-intl’s useIntl() and returns only the formatTime function.

useMakeQuoteActive

Hook to use to make a request to set a quote as active. This will make the quote active in the app’s state and change the quote’s status to EDITING if not already one of the following statuses:

  • DRAFTING

  • EDITING

  • PUBLISHED

  • ASSIGNED

Props

An object containing the following:

  • quoteClient: The client used to make the request.

    • This comes from the @broadleaf/commerce-cart SDK.

  • setCart: The callback needed to handle setting the app’s cart state.

    • (cart: Cart | null) ⇒ void

Response

An object containing the following:

  • makeQuoteActive: Method to send the request. Takes the quote type cart to make active.

    • (selectedQuote: Cart) ⇒ Promise<void>

  • error: Any error produced by the request.

    • ApiError | unknown

useUserOperations

Hook to use to make a request to fetch the allowed user operations for the specified scopes.

Props

  • scope: The scope or scopes to check for.

    • string | string[]

Response

An object containing the following:

  • userOperationInfo: The user operation info if no error is encountered.

  • errorUserOperations: Any error produced by the request.

    • ApiError | unknown

  • loading: Whether the request is in progress.

    • boolean

  • refetch: Function to resend the request.

    • () ⇒ Promise<UserOperationInformation | undefined>

useGetCustomerAccessToken

Hook to use to make a request to fetch an access token for the customer or CSR.

Props

None.

Response

A function to use to fetch the access token:

(options?: GetAccessTokenOptions) => Promise<string | undefined>

useUpdateQuoteInfo

Hook to use to make a request to update a quote’s name or expiration date. Only sellers can set the latter field.

Props

An object containing the following:

  • quoteClient: The client used to make the request.

    • This comes from the @broadleaf/commerce-cart SDK.

Response

An object containing the following:

  • updateQuoteInfo: Function to make the request.

  • quote: The updated quote.

    • Cart

  • error: Any error produced by the request.

    • ApiError | unknown

useIsSeller

Hook to use to make a check if the currently authenticated user is a seller (CSR).

Props

None.

Response

Boolean.

useDeleteQuote

Hook to use to make a request to delete a quote by id. Only for sellers.

Props

An object containing the following:

  • quoteClient: The client used to make the request.

    • This comes from the @broadleaf/commerce-cart SDK.

Response

An object containing the following:

  • deleteQuote: Function to make the request.

    • (selectedQuote: Cart) ⇒ Promise<void>

  • error: Any error produced by the request.

    • ApiError | unknown

useChangeQuoteStatus

Hook to use to make a request to change a quote’s status.

Props

An object containing the following:

  • quoteClient: The client used to make the request.

    • This comes from the @broadleaf/commerce-cart SDK.

Response

An object containing the following:

  • changeQuoteStatus: Function to make the request.

    • (selectedQuote: Cart, status: string) ⇒ Promise<void>

  • error: Any error produced by the request.

    • ApiError | unknown