-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pci.instances): use shell to navigate to public-ip (#13948)
ref: TAPC-876 Signed-off-by: Yann Lojewski <[email protected]>
- Loading branch information
Showing
4 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/manager/apps/pci-public-ip/src/pages/order/hooks/useParams.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useMemo } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import { TInstance } from '@ovh-ux/manager-pci-common'; | ||
import { TDataState } from '@/api/hooks/useData'; | ||
import { IPTypeEnum, TCountry, TRegion } from '@/api/types'; | ||
|
||
export type OrderParams = { | ||
ipType: IPTypeEnum | null; | ||
failoverCountry: TCountry | null; | ||
floatingRegion: TRegion | null; | ||
instance: TInstance | null; | ||
}; | ||
|
||
export const useOrderParams = (state: TDataState) => { | ||
const [searchParams] = useSearchParams(); | ||
|
||
return useMemo((): OrderParams => { | ||
const searchParamsIpType = searchParams.get('ipType') as IPTypeEnum; | ||
const searchParamsRegion = searchParams.get('region'); | ||
const searchParamsInstance = searchParams.get('instance'); | ||
|
||
let ipType: IPTypeEnum | null = null; | ||
let failoverCountry: TCountry | null = null; | ||
let floatingRegion: TRegion | null = null; | ||
let instance: TInstance | null = null; | ||
|
||
if (Object.values(IPTypeEnum).includes(searchParamsIpType)) { | ||
ipType = searchParamsIpType; | ||
} | ||
|
||
if (ipType === IPTypeEnum.FAILOVER && searchParamsRegion) { | ||
failoverCountry = state.countries.find( | ||
({ name }) => name === searchParamsRegion, | ||
); | ||
} | ||
|
||
if (ipType === IPTypeEnum.FLOATING && searchParamsRegion) { | ||
floatingRegion = state.regions.find( | ||
({ name }) => name === searchParamsRegion, | ||
); | ||
} | ||
|
||
if (searchParamsInstance) { | ||
instance = state.instances.all.find( | ||
({ id }) => id === searchParamsInstance, | ||
); | ||
} | ||
|
||
return { | ||
ipType, | ||
failoverCountry, | ||
floatingRegion, | ||
instance, | ||
}; | ||
}, [searchParams, state.countries, state.instances.all, state.regions]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters