Skip to content

Commit

Permalink
feat(pci-databases-analytics): fix pr comments
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Bullet <[email protected]>
  • Loading branch information
abullet33 committed Oct 10, 2024
1 parent f324750 commit 82983e9
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import { CdbError, ServiceData } from '@/data/api/database';

interface UseDeleteService {
onError: (cause: CdbError) => void;
onSuccess: () => void;
onDeleteSuccess: () => void;
}

export function useDeleteService({ onError, onSuccess }: UseDeleteService) {
export function useDeleteService({
onError,
onDeleteSuccess,
}: UseDeleteService) {
const queryClient = useQueryClient();
const { projectId } = useParams();
const mutation = useMutation({
Expand All @@ -18,7 +21,7 @@ export function useDeleteService({ onError, onSuccess }: UseDeleteService) {
},
onError,
onSuccess: () => {
onSuccess();
onDeleteSuccess();
// Invalidate service list query to get the latest data
queryClient.invalidateQueries({
queryKey: [projectId, 'database/service'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ describe('useDeleteService', () => {
const projectId = 'projectId';
const engine = database.EngineEnum.mysql;
const serviceId = 'serviceId';
const onSuccess = vi.fn();
const onDeleteSuccess = vi.fn();
const onError = vi.fn();

vi.mocked(databaseAPI.deleteService).mockResolvedValue(undefined);

const { result } = renderHook(
() => useDeleteService({ onError, onSuccess }),
() => useDeleteService({ onError, onDeleteSuccess }),
{ wrapper: QueryClientWrapper },
);

Expand All @@ -35,7 +35,7 @@ describe('useDeleteService', () => {
expect(databaseAPI.deleteService).toHaveBeenCalledWith(
deleteServiceProps,
);
expect(onSuccess).toHaveBeenCalledWith();
expect(onDeleteSuccess).toHaveBeenCalledWith();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { CdbError } from '@/data/api/database';

interface UseEditService {
onError: (cause: CdbError) => void;
onSuccess: (service: database.Service) => void;
onEditSuccess: (service: database.Service) => void;
}
export function useEditService({ onError, onSuccess }: UseEditService) {
export function useEditService({ onError, onEditSuccess }: UseEditService) {
const queryClient = useQueryClient();
const { projectId } = useParams();
const mutation = useMutation({
mutationFn: (serviceUpdate: EditService) => editService(serviceUpdate),
onError,
onSuccess: (data: database.Service) => {
onSuccess(data);
onEditSuccess(data);
// Invalidate service list query to get the latest data
queryClient.invalidateQueries({
queryKey: [projectId, 'database/service'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe('useEditService', () => {
const projectId = 'projectId';
const engine = database.EngineEnum.mysql;
const serviceId = 'serviceId';
const onSuccess = vi.fn();
const onEditSuccess = vi.fn();
const onError = vi.fn();

vi.mocked(databaseAPI.editService).mockResolvedValue(mockedService);
const { result } = renderHook(
() => useEditService({ onError, onSuccess }),
() => useEditService({ onError, onEditSuccess }),
{ wrapper: QueryClientWrapper },
);

Expand All @@ -38,7 +38,7 @@ describe('useEditService', () => {

await waitFor(() => {
expect(databaseAPI.editService).toHaveBeenCalledWith(editServiceProps);
expect(onSuccess).toHaveBeenCalledWith(mockedService);
expect(onEditSuccess).toHaveBeenCalledWith(mockedService);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const DeleteService = ({
onError(err);
}
},
onSuccess: () => {
onDeleteSuccess: () => {
track(
TRACKING.deleteService.success(service.engine, service.nodes[0].region),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const RenameService = ({
onError(err);
}
},
onSuccess: (renamedService) => {
onEditSuccess: (renamedService) => {
toast.toast({
title: t('renameServiceToastSuccessTitle'),
description: t('renameServiceToastSuccessDescription', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const IpsRestrictionsUpdate = ({
description: getCdbApiErrorMessage(err),
});
},
onSuccess: (updatedService) => {
onEditSuccess: (updatedService) => {
toast.toast({
title: t('ipsUpdateSuccessTitle'),
description: t('ipsUpdateSuccessDescription'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ServiceConfiguration = () => {
description: getCdbApiErrorMessage(err),
});
},
onSuccess: () => {
onEditSuccess: () => {
toast.toast({
title: t('serviceConfigurationUpdateToastSuccessTitle'),
description: t('serviceConfigurationUpdateToastSuccessDescription'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const UpdateFlavorContent = ({
onError(err);
}
},
onSuccess: (updatedService) => {
onEditSuccess: (updatedService) => {
toast.toast({
title: t('updateFlavorToastSuccessTitle'),
description: hasStorage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const UpdatePlanContent = ({
onError(err);
}
},
onSuccess: (updatedService) => {
onEditSuccess: (updatedService) => {
toast.toast({
title: t('updatePlanToastSuccessTitle'),
description: t('updatePlanToastSuccessDescription', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const UpdateVersionContent = ({
onError(err);
}
},
onSuccess: (updatedService) => {
onEditSuccess: (updatedService) => {
toast.toast({
title: t('updateVersionToastSuccessTitle'),
description: t('updateVersionToastSuccessDescription', {
Expand Down

0 comments on commit 82983e9

Please sign in to comment.