mirror of https://github.com/langgenius/dify.git
simplify pricing modal history handling
This commit is contained in:
parent
9f3a148732
commit
dee2492350
|
|
@ -119,7 +119,7 @@ describe('useQueryParams hooks', () => {
|
|||
expect(update.searchParams.has(PRICING_MODAL_QUERY_PARAM)).toBe(false)
|
||||
})
|
||||
|
||||
it('should use replace history when closing', async () => {
|
||||
it('should use push history when closing', async () => {
|
||||
// Arrange
|
||||
const { result, onUrlUpdate } = renderWithAdapter(
|
||||
() => usePricingModal(),
|
||||
|
|
@ -134,7 +134,7 @@ describe('useQueryParams hooks', () => {
|
|||
// Assert
|
||||
await waitFor(() => expect(onUrlUpdate).toHaveBeenCalled())
|
||||
const update = onUrlUpdate.mock.calls[onUrlUpdate.mock.calls.length - 1][0]
|
||||
expect(update.options.history).toBe('replace')
|
||||
expect(update.options.history).toBe('push')
|
||||
})
|
||||
|
||||
it('should respect explicit history options when provided', async () => {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ const parseAsPricingModal = createParser<boolean>({
|
|||
parse: value => (value === PRICING_MODAL_QUERY_VALUE ? true : null),
|
||||
serialize: value => (value ? PRICING_MODAL_QUERY_VALUE : ''),
|
||||
})
|
||||
.withDefault(false)
|
||||
.withOptions({ history: 'push' })
|
||||
|
||||
/**
|
||||
* Hook to manage pricing modal state via URL
|
||||
|
|
@ -47,13 +49,12 @@ const parseAsPricingModal = createParser<boolean>({
|
|||
export function usePricingModal() {
|
||||
const [isOpen, setIsOpenState] = useQueryState(
|
||||
PRICING_MODAL_QUERY_PARAM,
|
||||
parseAsPricingModal.withDefault(false),
|
||||
parseAsPricingModal,
|
||||
)
|
||||
|
||||
const setIsOpen = useCallback(
|
||||
(open: boolean, options?: Options) => {
|
||||
const history = options?.history ?? (open ? 'push' : 'replace')
|
||||
setIsOpenState(open ? true : null, { ...options, history })
|
||||
setIsOpenState(open, options)
|
||||
},
|
||||
[setIsOpenState],
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue