-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathStdcmWarningBox.tsx
69 lines (61 loc) · 1.92 KB
/
StdcmWarningBox.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { useEffect, useRef } from 'react';
import { Button } from '@osrd-project/ui-core';
import { Alert } from '@osrd-project/ui-icons';
import cx from 'classnames';
import { useTranslation } from 'react-i18next';
import { StdcmConfigErrorTypes, type StdcmConfigErrors } from '../types';
const SHORT_TEXT_ERRORS = [
StdcmConfigErrorTypes.INFRA_NOT_LOADED,
StdcmConfigErrorTypes.MISSING_LOCATION,
];
type StdcmWarningBoxProps = {
errorInfos: {
errorType: StdcmConfigErrorTypes;
errorDetails?: StdcmConfigErrors['errorDetails'];
};
removeOriginArrivalTime: () => void;
removeDestinationArrivalTime: () => void;
};
const StdcmWarningBox = ({
errorInfos: { errorType, errorDetails },
removeOriginArrivalTime,
removeDestinationArrivalTime,
}: StdcmWarningBoxProps) => {
const { t } = useTranslation('stdcm');
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (errorType && errorType !== StdcmConfigErrorTypes.MISSING_LOCATION && ref.current) {
ref.current.scrollIntoView({ behavior: 'smooth' });
}
}, [errorType]);
return (
<div ref={ref} data-testid="warning-box" className="warning-box">
<span>
<Alert variant="fill" size="lg" />
</span>
<p
className={cx('mb-0', {
'text-center': SHORT_TEXT_ERRORS.includes(errorType),
'text-justify': !SHORT_TEXT_ERRORS.includes(errorType),
})}
>
{t(`stdcmErrors.${errorType}`)}
</p>
{errorType === 'bothPointAreScheduled' && errorDetails && (
<div className="stdcm-warning-buttons">
<Button
type="button"
onClick={removeDestinationArrivalTime}
label={errorDetails.originTime}
/>
<Button
type="button"
onClick={removeOriginArrivalTime}
label={errorDetails.destinationTime}
/>
</div>
)}
</div>
);
};
export default StdcmWarningBox;