Skip to content

Commit b563672

Browse files
Fleur CastelSteffy29
authored andcommitted
fix(network-ip): fix order button display and geolocation reset on quantity change
ref: #MANAGER-19813 Signed-off-by: Fleur Castel <fleur.castel.ext@corp.ovh.com>
1 parent 99c132f commit b563672

3 files changed

Lines changed: 40 additions & 14 deletions

File tree

packages/manager/apps/ips/src/data/hooks/catalog/useAvailableGeolocationFromPlanCode.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,31 @@ export const useAvailableGeolocationFromPlanCode = ({
1414
planCode,
1515
serviceName,
1616
serviceType,
17+
ipQuantity,
1718
}: {
1819
planCode?: string;
1920
serviceName?: string | null;
2021
serviceType?: ServiceType;
22+
ipQuantity?: number;
2123
}) => {
2224
const { environment } = React.useContext(ShellContext);
25+
const hasMultipleIps = (ipQuantity ?? 1) > 1;
2326
const { data, ...query } = useCatalogIps({
2427
subsidiary: environment.user.ovhSubsidiary,
2528
enabled:
2629
!!serviceType &&
27-
![ServiceType.dedicatedCloud, ServiceType.vps].includes(serviceType),
30+
(![ServiceType.dedicatedCloud, ServiceType.vps].includes(serviceType) ||
31+
hasMultipleIps),
2832
});
2933

34+
const catalogGeolocations =
35+
data?.data?.plans
36+
?.find((plan: CatalogIpPlan) => plan.planCode === planCode)
37+
?.details.product.configurations.find(
38+
(config: CatalogIpConfiguration) => config.name === 'country',
39+
)
40+
?.values.map((v: string) => v.toLowerCase()) || [];
41+
3042
const { data: dedicatedServerData, ...dedicatedServerQuery } =
3143
useDedicatedServerGeolocations({
3244
serviceName,
@@ -51,28 +63,28 @@ export const useAvailableGeolocationFromPlanCode = ({
5163
case ServiceType.server:
5264
return {
5365
...dedicatedServerQuery,
54-
geolocations: dedicatedServerData?.data || [],
66+
geolocations: hasMultipleIps
67+
? catalogGeolocations
68+
: dedicatedServerData?.data || [],
5569
};
5670
case ServiceType.dedicatedCloud:
5771
return {
5872
...pccQuery,
59-
geolocations: pccData?.data || [],
73+
geolocations: hasMultipleIps
74+
? catalogGeolocations
75+
: pccData?.data || [],
6076
};
6177
case ServiceType.vps:
6278
return {
6379
...vpsQuery,
64-
geolocations: vpsData?.data || [],
80+
geolocations: hasMultipleIps
81+
? catalogGeolocations
82+
: vpsData?.data || [],
6583
};
6684
default:
6785
return {
6886
...query,
69-
geolocations:
70-
data?.data?.plans
71-
?.find((plan: CatalogIpPlan) => plan.planCode === planCode)
72-
?.details.product.configurations.find(
73-
(config: CatalogIpConfiguration) => config.name === 'country',
74-
)
75-
?.values.map((v: string) => v.toLowerCase()) || [],
87+
geolocations: catalogGeolocations,
7688
};
7789
}
7890
};

packages/manager/apps/ips/src/pages/order/sections/GeolocationSection.component.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@ export const GeolocationSection: React.FC = () => {
2727
selectedServiceType,
2828
setSelectedGeolocation,
2929
selectedOffer,
30+
ipQuantity,
3031
} = React.useContext(OrderContext);
3132
const { t } = useTranslation(TRANSLATION_NAMESPACES.order);
3233
const { trackClick } = useOvhTracking();
3334
const { geolocations } = useAvailableGeolocationFromPlanCode({
3435
serviceName: selectedService,
3536
serviceType: selectedServiceType,
3637
planCode: selectedPlanCode,
38+
ipQuantity,
3739
});
3840
const isDisabled =
3941
!geolocations ||
4042
geolocations.length < 2 ||
4143
(selectedOffer === IpOffer.additionalIp &&
42-
ServiceType.ipParking === selectedServiceType);
44+
ServiceType.ipParking === selectedServiceType &&
45+
ipQuantity === 1);
4346

4447
return (
4548
<OrderSection

packages/manager/apps/ips/src/pages/order/sections/OfferSelectionSection.component.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,23 @@ export const OfferSelectionSection: React.FC = () => {
103103
});
104104
}}
105105
>
106-
<div className="flex min-h-14 flex-col justify-center">
106+
<div
107+
className="flex min-h-14 flex-col justify-center"
108+
onClick={(event) => event.stopPropagation()}
109+
onKeyDown={(event) => event.stopPropagation()}
110+
role="presentation"
111+
>
107112
<OdsQuantity
108113
name="additional_ip_quantity"
109114
min={MIN_IP_QUANTITY}
110115
max={MAX_IP_QUANTITY}
111-
onOdsChange={(event) => setIpQuantity(event.target.value)}
116+
onOdsChange={(event) => {
117+
if (selectedOffer !== IpOffer.additionalIp) {
118+
setSelectedOffer(IpOffer.additionalIp);
119+
setSelectedPlanCode(additionalIpPlanCode);
120+
}
121+
setIpQuantity(Number(event.target.value));
122+
}}
112123
value={ipQuantity}
113124
/>
114125
<OdsText preset={ODS_TEXT_PRESET.heading4}>

0 commit comments

Comments
 (0)