Skip to content

Commit

Permalink
fix: reset url session storage when searching new cities
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkynrg committed Aug 15, 2024
1 parent c8c47fb commit ed9ea8a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/Request/Request.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import classnames from 'classnames'
import { useEffect, useState } from 'react'
import { useLocalStorage } from 'usehooks-ts'
import { useLocalStorage, useSessionStorage } from 'usehooks-ts'
import { TreeSelect, Button } from 'antd'
import { Navigate } from 'react-router-dom'
import { Location, RequestResponse } from '../../types'
Expand All @@ -24,6 +24,7 @@ const Request = ({
const [request, setRequest] = useLocalStorage<string | null>('requestUUID', null)
const [error, setError] = useState<string | null>(null)
const [codes, setCodes] = useState(null)
const [_, setUrl] = useSessionStorage<string | null>('url', null)

const handleRequest = () => {
axios.post<RequestResponse>('/v1/request', { codes }).then((response) => {
Expand Down Expand Up @@ -55,6 +56,10 @@ const Request = ({
})
}, [setCitiesTree])

useEffect(() => {
setUrl(null)
}, [setUrl])

if (request) {
return <Navigate to={`/listing/${request}`} replace />
}
Expand Down

0 comments on commit ed9ea8a

Please sign in to comment.