-
Notifications
You must be signed in to change notification settings - Fork 2
/
ViewJob.tsx
285 lines (272 loc) · 8.25 KB
/
ViewJob.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import { useEffect, useState } from 'react';
import GenericApiService from '../../service/GenericApiService';
import Job from '../../dto/Job';
import { Card, CardBody } from '@chakra-ui/card';
import {
Box,
Image,
Button,
Flex,
Heading,
SimpleGrid,
Skeleton,
Stack,
Text,
CardFooter,
useDisclosure,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalCloseButton,
ModalBody,
ModalFooter,
} from '@chakra-ui/react';
import { useNavigate, useParams } from 'react-router-dom';
import UserService from '../../service/UserService';
import Stars from './Stars';
import JobService from '../../service/JobService';
import Title from './Header';
import JobConst from '../../consts/JobConst';
import DateUtil from '../../service/DateUtil';
import Room from '../../dto/Room';
import UserJobItemEditPanel from './panels/UserJobItemEditPanel';
import UserJobItemPanel from './panels/UserJobItemPanel';
import AdminJobItemPanel from './panels/AdminJobItemPanel';
interface Props {}
export default function ViewOfferRequest({}: Props) {
const [job, setJob] = useState<Job>();
const [imageLoaded, setImageLoaded] = useState(false);
const { isOpen, onOpen, onClose } = useDisclosure();
const navigate = useNavigate();
const [modalImage, setModalImage] = useState<string>();
let { id, scope, status } = useParams();
const scopeFromUrl = scope || 'public';
useEffect(() => {
GenericApiService.get<Job>(
status !== undefined
? `api/v1/job/${scopeFromUrl}/admin/jobStatus/${status}/jobId/${id}`
: `api/v1/job/${scopeFromUrl}/jobId/${id}`
).then((job: Job) => {
setJob(job);
});
}, []);
const showJobStatus =
job &&
(UserService.isAdmin() || UserService.isPublisher(job)) &&
scope !== JobConst.SCOPE_PUBLIC;
const openModalByImage = (imageName: string | undefined) => {
if (imageName) {
setModalImage(imageName);
onOpen();
}
};
const calculateTitle = (type: number | undefined): string => {
if (type === 0) {
return 'Offer';
}
if (type === 1) {
return 'Request';
}
return '';
};
const retrieveFirstname = job && job.author?.firstname;
const retrieveLastName = job && job.author?.lastname;
function goToConversation(job: Job): void {
if (job.author && UserService.isSameUsername(job.author?.username)) {
return;
}
GenericApiService.get<Room>(`api/v1/room/jobId/${job.id}`).then(
(room: Room) => {
navigate(`/rooms/${room?.id}`);
}
);
}
const calculateUserIdColor = (job: Job) => {
if (job.author && UserService.isSameUsername(job.author?.username)) {
return 'gray.600';
}
return 'blue.400';
};
const goToViewOfferRequest = (job: Job) => {
window.scrollTo(0, 0);
if (job.type == JobConst.TYPE_OFFER) {
navigate('/offers');
} else if (job.type == JobConst.TYPE_REQUEST) {
navigate('/requests');
}
};
return (
<>
{job && <Title title={calculateTitle(job?.type)} />}
<Card
direction={{ base: 'column', sm: 'row' }}
overflow="hidden"
variant="outline"
>
{JobPicture(job, imageLoaded, openModalByImage, setImageLoaded)}
<SimpleGrid columns={{ base: 1, md: 2 }} w={'full'}>
<Stack spacing={4} w={'full'}>
<CardBody>
<Heading
cursor={'pointer'}
color={'green.400'}
_hover={{ color: 'greeen.500' }}
size="md"
>
{job && job.title}{' '}
</Heading>
<Box fontSize={'0.8em'}>
#{job?.id}
{' | '}
by {retrieveFirstname} {retrieveLastName} (
<Box
as="span"
color={job && calculateUserIdColor(job)}
cursor={'pointer'}
userSelect={'none'}
onClick={() => job && goToConversation(job)}
>
@{job && job.author?.username})
</Box>{' '}
on {(job && DateUtil.transformDate(job.lastModifiedDate)) || ''}
{' | '} <Stars num={job && job.author?.stars} />
</Box>
<Text py="2">{job && job.description}</Text>
</CardBody>
<CardFooter justify={'left'}>
<SimpleGrid maxW={'100%'} columns={4} spacing={2}>
{job &&
job.jobPictureList &&
job.jobPictureList.map((image, idx) => (
<Box
onClick={() => openModalByImage(image.pictureName)}
key={idx}
mr={5}
maxW={'64px'}
maxH={'64px'}
borderRadius={'10px'}
boxShadow={'md'}
>
<Image
boxSize="64px"
objectFit="cover"
src={JobService.getImageLink(image.pictureName)}
/>
</Box>
))}
</SimpleGrid>
</CardFooter>
</Stack>
<Flex w={'full'}>
<Box
borderRadius={'10px'}
verticalAlign={'top'}
w={'full'}
textAlign={'right'}
p={10}
>
{showJobStatus && <JobStatus job={job} />}
<Box textAlign={'right'}>Price:</Box>
<Box fontSize={'1.3em'} fontWeight={'bold'}>
{job && job.price}€
</Box>
{job && scope && (
<Box mt={4}>
<UserJobItemEditPanel job={job} scope={scope} />
<UserJobItemPanel job={job} />
<AdminJobItemPanel
job={job}
scope={scope}
approveCallback={goToViewOfferRequest}
/>
</Box>
)}
</Box>
</Flex>
</SimpleGrid>
</Card>
{ModalShowPicture(isOpen, onClose, modalImage)}
</>
);
}
interface JobStatusProps {
job: Job;
}
function JobStatus({ job }: JobStatusProps) {
return (
<Box
color={
JobService.isCreated(job.status) || JobService.isUpdated(job.status)
? 'gray.400'
: 'green.400'
}
fontWeight={'bold'}
>
{JobService.retrieveStatus(job)}
</Box>
);
}
function JobPicture(
job: Job | undefined,
imageLoaded: boolean,
openModal: (string: string | undefined) => void,
setImageLoaded: any
) {
return (
<>
{JobService.hasMainJobPicture(job) && (
<Skeleton width={{ base: '100%', sm: '200px' }} isLoaded={imageLoaded}>
<Image
onClick={() => openModal(JobService.retrieveMainJobPicture(job))}
objectFit="cover"
maxW={{ base: '100%', sm: '200px' }}
h={{ base: '100%', sm: '100%' }}
src={JobService.getImageLink(
JobService.retrieveMainJobPicture(job)
)}
alt="Job Picture"
onLoad={() => setImageLoaded(true)}
/>
</Skeleton>
)}
{!JobService.hasMainJobPicture(job) && (
<Skeleton width={{ base: '100%', sm: '200px' }} isLoaded={imageLoaded}>
<Image
objectFit="cover"
maxW={{ base: '100%', sm: '200px' }}
h={{ base: '100%', sm: '100%' }}
src={JobService.getImageLink('no_image.png')}
alt="Job Picture"
onLoad={() => setImageLoaded(true)}
/>
</Skeleton>
)}
</>
);
}
function ModalShowPicture(
isOpen: boolean,
onClose: () => void,
modalImage: string | undefined
) {
return (
<Modal isOpen={isOpen} size={'full'} onClose={onClose}>
<ModalOverlay />
<ModalContent onClick={onClose}>
<ModalHeader>Modal Title</ModalHeader>
<ModalCloseButton />
<ModalBody>
<Box borderRadius={'10px'} boxShadow={'md'}>
<img src={JobService.getImageLink(modalImage)} />
</Box>
</ModalBody>
<ModalFooter>
<Button colorScheme="blue" mr={3} onClick={onClose}>
Close
</Button>
</ModalFooter>
</ModalContent>
</Modal>
);
}