Skip to content

Commit af1f0da

Browse files
committed
feat(ips): adding a modal to edit ip block information
ref: #MANAGER-20142 Signed-off-by: aderghamov <alexandre.dergham.ext@ovhcloud.com>
1 parent 73e1f41 commit af1f0da

File tree

16 files changed

+432
-0
lines changed

16 files changed

+432
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"ipBlockInformationTitle": "Informations du bloc d'IP",
3+
"ipBlockInformationSubtitle": "Cette section vous permet de personnaliser les informations publiques sur votre bloc IP (informations présentes sur la base whois).",
4+
"ipBlockInformationNetNameLabel": "Nom du réseau (Netname)",
5+
"ipBlockInformationDescriptionLabel": "Description",
6+
"ipBlockInformationOrganisationLabel": "Organisation",
7+
"ipBlockInformationOrganisationOnGoingChange": "L'organisation du bloc d'IP est en cour de réaffectation. Veuillez patienter quelques minutes.",
8+
"ipBlockInformationUpdateSuccessMessage": "Les informations du bloc d'IP {{ip}} ont été mises à jour.",
9+
"ipBlockInformationUpdateErrorMessage": "Une erreur a eu lieu pendant la mise à jour des informations du bloc d'IP {{ip}}: {{error}}",
10+
"ipBlockInformationOrgUpdateSuccessMessage": "Le bloc d'IP {{ip}} est en cours d'affectation à l'organisation {{organisation}}. Cette operation peut prendre quelques minutes",
11+
"ipBlockInformationOrgUpdateErrorMessage": "Une erreur a eu lieu pendant l'affectation du bloc IP {{ip}} à l'organisation {{organisation}}: {{error}}"
12+
}

packages/manager/apps/ips/public/translations/listing/Messages_fr_FR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"listingActionEditDescription": "Editer la description",
7777
"listingActionDeleteVirtualMac": "Supprimer la MAC virtuelle",
7878
"listingActionByoipTerminate": "Résilier le service BYOIP",
79+
"listingActionUpdateIpBlockInformation": "Voir / Modifier les informations sur le bloc IP",
7980
"listingActionSlice": "Segmenter",
8081
"listingActionAggregate": "Agréger",
8182
"listingActionUnblockHackedIP": "Déblocage anti-hack",

packages/manager/apps/ips/src/data/api/get/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export * from './organisationsList';
1414
export * from './organisationsDetails';
1515
export * from './byoip';
1616
export * from './productServices';
17+
export * from './ipRipeInformation';
1718
export * from './ipTask';
1819
export * from './moveIp';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ApiResponse, apiClient } from '@ovh-ux/manager-core-api';
2+
3+
export type IpRipeInformation = {
4+
description: string;
5+
netname: string;
6+
};
7+
8+
export type GetIpRipeInformationParams = {
9+
ip: string;
10+
};
11+
12+
export const getIpRipeInformationQueryKey = (
13+
params: GetIpRipeInformationParams,
14+
) => [`get/ip/${encodeURIComponent(params.ip)}/ripe`];
15+
16+
/**
17+
* Get IP Ripe Information
18+
*/
19+
export const getIpRipeInformation = async (
20+
params: GetIpRipeInformationParams,
21+
): Promise<ApiResponse<IpRipeInformation>> =>
22+
apiClient.v6.get<IpRipeInformation>(
23+
`/ip/${encodeURIComponent(params.ip)}/ripe`,
24+
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ApiResponse, apiClient } from '@ovh-ux/manager-core-api';
2+
3+
export type ChangeIpOrganisationParams = {
4+
ip: string;
5+
organisation: string;
6+
};
7+
8+
export const changeIpOrganisationQueryKey = (
9+
params: ChangeIpOrganisationParams,
10+
) => [`post/ip/${encodeURIComponent(params.ip)}/changeOrg`];
11+
12+
export const changeIpOrganisation = async (
13+
params: ChangeIpOrganisationParams,
14+
): Promise<ApiResponse<void>> => {
15+
return apiClient.v6.post<void>(
16+
`/ip/${encodeURIComponent(params.ip)}/changeOrg`,
17+
{
18+
organisation: params.organisation,
19+
},
20+
);
21+
};

packages/manager/apps/ips/src/data/api/postorput/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ export * from './addIpToVirtualMac';
77
export * from './postMoveIp';
88
export * from './unblockAntiHackIp';
99
export * from './unblockAntiSpamIp';
10+
export * from './upsertIpRipeInformation';
11+
export * from './changeIpOrganisation';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApiResponse, apiClient } from '@ovh-ux/manager-core-api';
2+
3+
export type UpsertIpRipeInformationParams = {
4+
ip: string;
5+
description: string;
6+
netname: string;
7+
};
8+
9+
export const upsertIpRipeInformationQueryKey = (
10+
params: UpsertIpRipeInformationParams,
11+
) => [`put/ip/${encodeURIComponent(params.ip)}/ripe`];
12+
13+
export const upsertIpRipeInformation = async (
14+
params: UpsertIpRipeInformationParams,
15+
): Promise<ApiResponse<void>> => {
16+
return apiClient.v6.put<void>(`/ip/${encodeURIComponent(params.ip)}/ripe`, {
17+
description: params.description,
18+
netname: params.netname,
19+
});
20+
};

packages/manager/apps/ips/src/data/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './ip';
2+
export * from './organisation';
23
export * from './useGetTokens';
34
export * from './useIpv6Availability';
45
export * from './useGetProductService';

packages/manager/apps/ips/src/data/hooks/ip/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from './useGetIpVmacDetails';
66
export * from './useGetIpVmacWithIp';
77
export * from './useGetIpMitigation';
88
export * from './useGetIpGameFirewall';
9+
export * from './useGetIpOrganisation';
910
export * from './useIpHasAlerts';
1011
export * from './useGetIpAntihack';
1112
export * from './useGetIpSpam';
@@ -24,3 +25,4 @@ export * from './useMoveIpService';
2425
export * from './useGetDedicatedServerTasks';
2526
export * from './useByoipActions';
2627
export * from './edge-firewall';
28+
export * from './useGetIpRipeInformation';
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { useQuery, useQueries } from '@tanstack/react-query';
2+
import { ApiError, ApiResponse } from '@ovh-ux/manager-core-api';
3+
import {
4+
IpDetails,
5+
getIpDetailsQueryKey,
6+
getIpDetails,
7+
getIpTaskQueryKey,
8+
getIpTaskList,
9+
} from '@/data/api';
10+
import { IpTaskFunction, IpTaskStatus } from '@/types';
11+
12+
export type UseGetIpOrganisationParams = {
13+
ip: string;
14+
enabled?: boolean;
15+
};
16+
17+
export const useGetIpOrganisation = ({
18+
ip,
19+
enabled = true,
20+
}: UseGetIpOrganisationParams) => {
21+
const taskQueries = useQueries({
22+
queries: [IpTaskStatus.init, IpTaskStatus.todo, IpTaskStatus.doing].map(
23+
(status) => ({
24+
queryKey: getIpTaskQueryKey({
25+
ip,
26+
status,
27+
fn: IpTaskFunction.changeRipeOrg,
28+
}),
29+
queryFn: () =>
30+
getIpTaskList({
31+
ip,
32+
status,
33+
fn: IpTaskFunction.changeRipeOrg,
34+
}),
35+
staleTime: 0,
36+
}),
37+
),
38+
});
39+
40+
const isTasksLoading = taskQueries.some((query) => query.isLoading);
41+
const taskError = taskQueries.find((query) => query.isError)?.error;
42+
const hasOnGoingChangeRipeOrgTask = taskQueries.some(
43+
(query) => query.data?.data && query.data.data.length > 0,
44+
);
45+
46+
const { data: ipDetailsResponse, isLoading, isError, error } = useQuery<
47+
ApiResponse<IpDetails>,
48+
ApiError
49+
>({
50+
queryKey: getIpDetailsQueryKey({ ip }),
51+
queryFn: () => getIpDetails({ ip }),
52+
enabled:
53+
enabled && !isTasksLoading && !taskError && !hasOnGoingChangeRipeOrgTask,
54+
staleTime: Number.POSITIVE_INFINITY,
55+
retry: false,
56+
});
57+
58+
return {
59+
organisationId: ipDetailsResponse?.data.organisationId,
60+
rirForOrganisation: ipDetailsResponse?.data.rir,
61+
hasOnGoingChangeRipeOrgTask,
62+
isLoading: isLoading || isTasksLoading,
63+
isError: isError || !!taskError,
64+
error: error ?? taskError,
65+
};
66+
};

0 commit comments

Comments
 (0)