-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoHistory.tsx
More file actions
77 lines (67 loc) · 2.03 KB
/
VideoHistory.tsx
File metadata and controls
77 lines (67 loc) · 2.03 KB
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
import { useQuery } from '@tanstack/react-query';
import { requestVideoHistoryListQuery, usersListQuery } from 'api/queries';
import { VideoStatusTag } from 'components/StatusTag/StatusTag';
import User from 'components/User/User';
import { Skeleton } from 'primereact/skeleton';
import HistoryComponent, { getHistory } from './History';
type VideoHistoryProps = {
requestId: number;
videoId: number;
};
const VideoFieldNames: Record<string, string> = {
additional_data: 'Egyéb adatok',
editor: 'Vágó',
status: 'Státusz',
title: 'Videó címe',
};
const VideoHistory = ({ requestId, videoId }: VideoHistoryProps) => {
const { data: queryResult } = useQuery(
requestVideoHistoryListQuery(requestId, videoId),
);
const { data: users } = useQuery(usersListQuery());
const data = getHistory(queryResult);
const getFieldName = (name: string) => {
return VideoFieldNames[name];
};
const getFieldValue = (name: string, value: string) => {
if (!value) {
return 'Nincs';
}
if (name === 'additional_data') {
const obj = JSON.parse(
value
.replace(/'/g, '"')
.replaceAll('True', 'true')
.replaceAll('False', 'false')
.replaceAll('None', 'null'),
);
return JSON.stringify(obj, null, 2);
}
if (name === 'editor') {
const user = users?.find((user) => user.id === Number(value));
if (!user)
return (
<div className="align-items-center flex flex-row gap-2">
<Skeleton shape="circle" size="32px" />
<Skeleton width="8rem" />
</div>
);
return <User name={user.full_name} imageUrl={user.avatar_url} />;
}
if (name === 'status') {
return <VideoStatusTag statusNum={Number(value)} />;
}
return value;
};
if (data.length) {
return (
<HistoryComponent
history={data}
getFieldName={getFieldName}
getFieldValue={getFieldValue}
/>
);
}
return <p>Nem történt még módosítás.</p>;
};
export default VideoHistory;