-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathStdcmLinkedPathSearch.tsx
123 lines (114 loc) · 3.54 KB
/
StdcmLinkedPathSearch.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { useState, type ReactNode } from 'react';
import { DatePicker, Input } from '@osrd-project/ui-core';
import { Gear } from '@osrd-project/ui-icons';
import { useTranslation } from 'react-i18next';
import useLinkedPathSearch from 'applications/stdcm/hooks/useLinkedPathSearch';
import StdcmCard from './StdcmCard';
import StdcmDefaultCard from './StdcmDefaultCard';
import StdcmLinkedPathResults from './StdcmLinkedPathResults';
import type { ExtremityPathStepType } from '../../types';
type StdcmLinkedPathSearchProps = {
disabled: boolean;
cardIcon: ReactNode;
cardName: string;
className?: string;
defaultCardText: string;
linkedOp: { extremityType: ExtremityPathStepType; id: string };
};
const StdcmLinkedPathSearch = ({
disabled,
cardIcon,
cardName,
className = '',
defaultCardText,
linkedOp,
}: StdcmLinkedPathSearchProps) => {
const { t } = useTranslation('stdcm');
const [displayLinkedPathSearch, setShowLinkedPathSearch] = useState(false);
const {
displaySearchButton,
launchTrainScheduleSearch,
linkedPathDate,
linkedPathResults,
resetLinkedPathSearch,
selectableSlot,
setDisplaySearchButton,
setLinkedPathDate,
setTrainNameInput,
trainNameInput,
} = useLinkedPathSearch();
const removeLinkedPathCard = () => {
setShowLinkedPathSearch(false);
resetLinkedPathSearch();
};
return (
<div className={`stdcm-linked-path-search-container ${className}`}>
{!displayLinkedPathSearch ? (
<StdcmDefaultCard
disabled={disabled}
text={defaultCardText}
Icon={cardIcon}
className="add-linked-path"
onClick={() => setShowLinkedPathSearch(true)}
/>
) : (
<StdcmCard
disabled={disabled}
name={cardName}
title={
<button type="button" onClick={removeLinkedPathCard}>
{t('translation:common.delete').toLowerCase()}
</button>
}
className="linked-path"
>
<div className="d-flex pr-1 pl-3">
<Input
id="linked-path-id"
type="text"
value={trainNameInput}
onChange={(e) => {
setDisplaySearchButton(true);
setTrainNameInput(e.target.value);
}}
label="N°"
/>
<DatePicker
inputProps={{
id: 'linked-path-date',
label: 'Date',
name: 'op-date',
}}
selectableSlot={selectableSlot}
value={linkedPathDate}
onDateChange={(date) => {
setLinkedPathDate(date);
}}
/>
</div>
{displaySearchButton && (
<button
className="stdcm-linked-path-button"
type="button"
onClick={launchTrainScheduleSearch}
>
{t('find')}
</button>
)}
{!displaySearchButton && !linkedPathResults && (
<div className="stdcm-linked-path-button white">
<Gear size="lg" className="stdcm-linked-path-loading" />
</div>
)}
{linkedPathResults &&
(linkedPathResults.length > 0 ? (
<StdcmLinkedPathResults linkedPathResults={linkedPathResults} linkedOp={linkedOp} />
) : (
<p className="text-center mb-0">{t('noCorrespondingResults')}</p>
))}
</StdcmCard>
)}
</div>
);
};
export default StdcmLinkedPathSearch;