Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ShellContext,
useNavigationGetUrl,
} from '@ovh-ux/manager-react-shell-client';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { ActionEnum, LifecycleActionsEnum } from '@/alldoms/enum/service.enum';
import { allDomManagerService, RENEW_URL } from '@/alldoms/constants';
import { hasTerminateAtExpirationDateAction } from '@/alldoms/utils/utils';
Expand All @@ -30,6 +30,7 @@ export default function ServiceActionMenu({
}: DatagridColumnActionMenuProps) {
const { t } = useTranslation('allDom');
const navigate = useNavigate();
const location = useLocation();

const {
environment: { user },
Expand Down Expand Up @@ -87,15 +88,17 @@ export default function ServiceActionMenu({
const terminateAction = {
id: 4,
label: t('allDom_table_action_terminate'),
onClick: () => navigate(terminateUrl),
onClick: () =>
navigate(terminateUrl, { state: { backgroundLocation: location } }),
color: ODS_BUTTON_COLOR.critical,
isDisabled: disableAction,
};

const cancelTerminate = {
id: 5,
label: t('allDom_table_action_cancel_terminate'),
onClick: () => navigate(cancelTerminateUrl),
onClick: () =>
navigate(cancelTerminateUrl, { state: { backgroundLocation: location } }),
};

let items = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { NAMESPACES } from '@ovh-ux/manager-common-translations';
import { useNavigate } from 'react-router-dom';
import {
Button,
BUTTON_VARIANT,
Expand All @@ -15,6 +13,7 @@ import {
import { ModalStepsProps } from '@/alldoms/types';
import DomainsCheckboxList from '@/alldoms/components/terminate/DomainsCheckboxes/DomainsCheckboxList';
import { hasTerminateAtExpirationDateAction } from '@/alldoms/utils/utils';
import { useCloseModal } from '@/common/hooks/closeModal/useCloseModal';

export default function TerminateModalStepOne({
services,
Expand All @@ -25,7 +24,7 @@ export default function TerminateModalStepOne({
setCheckAllDomains,
}: Readonly<ModalStepsProps>) {
const { t } = useTranslation(['allDom', NAMESPACES.ACTIONS]);
const navigate = useNavigate();
const closeModal = useCloseModal();

return (
<div>
Expand Down Expand Up @@ -78,7 +77,7 @@ export default function TerminateModalStepOne({
</Message>

<div className="flex justify-end gap-x-6">
<Button variant={BUTTON_VARIANT.ghost} onClick={() => navigate(-1)}>
<Button variant={BUTTON_VARIANT.ghost} onClick={closeModal}>
{t(`${NAMESPACES.ACTIONS}:close`)}
</Button>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useNotifications } from '@ovh-ux/manager-react-components';
import { useTranslation } from 'react-i18next';
import { NAMESPACES } from '@ovh-ux/manager-common-translations';
import { useNavigate } from 'react-router-dom';
import { updateService } from '@/alldoms/data/api/web-domains';
import {
ServiceInfoRenewMode,
Expand All @@ -11,6 +10,7 @@ import {
} from '@/alldoms/enum/service.enum';
import { TDomainsInfo } from '@/alldoms/types';
import { useGetServices } from '@/alldoms/hooks/data/useGetServices';
import { useCloseModal } from '@/common/hooks/closeModal/useCloseModal';

export const useCancelAllDomTerminate = (
serviceName: string,
Expand All @@ -19,7 +19,7 @@ export const useCancelAllDomTerminate = (
const { addError, addSuccess } = useNotifications();
const { t } = useTranslation(['allDom', NAMESPACES.ACTIONS]);
const queryClient = useQueryClient();
const navigate = useNavigate();
const closeModal = useCloseModal();

const { data: services } = useGetServices({
names: domains.map((domain) => domain.name),
Expand Down Expand Up @@ -60,16 +60,17 @@ export const useCancelAllDomTerminate = (
serviceName,
}),
);
navigate(-1);
},

onError: () => {
navigate(-1);
addError(
t('allDom_cancel_terminate_error', {
serviceName,
}),
);
},
onSettled: () => {
closeModal();
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useNotifications } from '@ovh-ux/manager-react-components';
import { useTranslation } from 'react-i18next';
import { NAMESPACES } from '@ovh-ux/manager-common-translations';
import { useNavigate } from 'react-router-dom';
import { updateService } from '@/alldoms/data/api/web-domains';
import {
ServiceInfoUpdateEnum,
ServiceRoutes,
} from '@/alldoms/enum/service.enum';
import { useCloseModal } from '@/common/hooks/closeModal/useCloseModal';

export const useTerminateService = (serviceName: string, domains: string[]) => {
const { addError, addSuccess } = useNotifications();
const { t } = useTranslation(['allDom', NAMESPACES.ACTIONS]);
const queryClient = useQueryClient();
const navigate = useNavigate();
const closeModal = useCloseModal();

return useMutation({
mutationFn: async () => {
Expand Down Expand Up @@ -46,7 +46,7 @@ export const useTerminateService = (serviceName: string, domains: string[]) => {
);
},
onSettled: () => {
navigate(-1);
closeModal();
},
});
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React from 'react';
import { Modal } from '@ovh-ux/manager-react-components';
import { useTranslation } from 'react-i18next';
import { useNavigate, useParams } from 'react-router-dom';
import { useParams } from 'react-router-dom';
import { NAMESPACES } from '@ovh-ux/manager-common-translations';
import { ODS_MODAL_COLOR } from '@ovhcloud/ods-components';
import { Spinner, SPINNER_SIZE, Text } from '@ovhcloud/ods-react';
import { useGetAllDomResource } from '@/alldoms/hooks/data/query';
import { useCancelAllDomTerminate } from '@/alldoms/hooks/useCancelAllDomTerminate/useCancelAllDomTerminate';
import { useCloseModal } from '@/common/hooks/closeModal/useCloseModal';

export default function ServiceCancelTerminate() {
const { t } = useTranslation(['allDom', NAMESPACES.ACTIONS]);
const { serviceName } = useParams<{ serviceName: string }>();
const navigate = useNavigate();
const closeModal = useCloseModal();
const { data: allDomResource, isLoading } = useGetAllDomResource(serviceName);

const cancelAllDomTerminate = useCancelAllDomTerminate(
Expand All @@ -28,7 +29,7 @@ export default function ServiceCancelTerminate() {
primaryLabel={t(`${NAMESPACES.ACTIONS}:confirm`)}
secondaryLabel={t(`${NAMESPACES.ACTIONS}:cancel`)}
onPrimaryButtonClick={() => cancelAllDomTerminate.mutate()}
onSecondaryButtonClick={() => navigate(-1)}
onSecondaryButtonClick={closeModal}
>
{isLoading ? (
<Spinner size={SPINNER_SIZE.xs} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useLocation, useNavigate } from 'react-router-dom';

/**
* Hook to close a modal by navigating back to the background location
* @returns A function to close the modal
*/
export const useCloseModal = () => {
const navigate = useNavigate();
const location = useLocation();

const closeModal = () => {
if (location.state?.backgroundLocation) {
navigate(location.state.backgroundLocation);
} else {
navigate(-1);
}
};

return closeModal;
};
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,21 @@ export default class EditOwnerFormFieldController {
// Returns a list of fields that are required to pass the validation rules.
// In some cases we need to return a list of fields even though the rule says otherwise.
isRequired() {
return Object.values(FORCED_FIELDS).includes(this.rule?.label) || !!this.rule?.constraints
.filter((constraint) => constraint.operator === 'required')
.find((rules) => {
if (rules?.conditions) {
return rules?.conditions?.and
? !rules?.conditions?.and
.map((rule) => this.checkConstraint(rule.fields))
.some((e) => e === false)
: this.checkConstraint(rules);
}
return !!rules;
});
return (
Object.values(FORCED_FIELDS).includes(this.rule?.label) ||
!!this.rule?.constraints
.filter((constraint) => constraint.operator === 'required')
.find((rules) => {
if (rules?.conditions) {
return rules?.conditions?.and
? !rules?.conditions?.and
.map((rule) => this.checkConstraint(rule.fields))
.some((e) => e === false)
: this.checkConstraint(rules);
}
return !!rules;
})
);
}

isReadOnly() {
Expand Down Expand Up @@ -227,35 +230,40 @@ export default class EditOwnerFormFieldController {
this.contactInformations,
this.rule.label,
);

if (this.rule.placeholder && !value) {
if (this.getFieldType() === 'select') {
this.value = {
key: this.rule.placeholder,
};
} else {
this.value = this.rule.placeholder;
const enums = this.getTranslatedEnums();

if (this.rule.label === this.FIELD_NAME_LIST.language) {
const languageKey = this.contactInformations.language;
this.value = enums.find((item) => item.key === languageKey) || null;
return;
}

if (this.rule.label === this.FIELD_NAME_LIST.country) {
const countryKey = this.contactInformations.country;
this.value = enums.find((item) => item.key === countryKey) || null;
}
}
}
}

// if rule has an initialValue, use it
setInitialValue() {
if (!this.rule || !this.contactInformations) return;
const enums = this.getTranslatedEnums();
const initialValue = this.getDescendantProp(
this.contactInformations,
this.rule.label,
);
if (initialValue) {
let value = angular.copy(initialValue);
if (this.getFieldType() === 'select') {
const translated = this.getFormattedTranslation(this.rule, value);
value = {
key: value,
translated,
};
} else if (this.getFieldType() === 'date') {
value = moment(initialValue, 'YYYY-MM-DD').toDate();
}
this.value = value;

if (this.getFieldType() === 'select') {
this.value = enums.find((item) => item.key === initialValue) || null;
} else if (this.getFieldType() === 'date') {
this.value = moment(initialValue, 'YYYY-MM-DD').toDate();
} else {
this.value = angular.copy(initialValue);
}
}

Expand Down Expand Up @@ -357,12 +365,7 @@ export default class EditOwnerFormFieldController {
translated,
};
})
.sort((a, b) => {
if (a.translated > b.translated) {
return 1;
}
return -1;
});
.sort((a, b) => a.translated.localeCompare(b.translated));

this.translatedEnumCache = result;
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
data-ng-pattern="$ctrl.inputValidator()"
data-ng-disabled="$ctrl.isReadOnly()"
data-ng-required="$ctrl.isRequired()"
placeholder="{{ $ctrl.rule.placeholder }}"
data-maxlength="$ctrl.rule.maxLength"
placeholder="{{ $ctrl.rule.placeholder }}"
/>

<!-- SELECT -->
Expand Down
Loading