-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathSentenceReportPreviewView.tsx
More file actions
151 lines (144 loc) · 5.57 KB
/
SentenceReportPreviewView.tsx
File metadata and controls
151 lines (144 loc) · 5.57 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
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
import { useSelector } from "@xstate/react";
import { Grid } from "@mui/material"
import React, { useContext } from "react";
import { ReviewTaskMachineContext } from "../../machines/reviewTask/ReviewTaskMachineProvider";
import { Roles } from "../../types/enums";
import {
reviewingSelector,
publishedSelector,
crossCheckingSelector,
reportSelector,
assignedSelector,
} from "../../machines/reviewTask/selectors";
import colors from "../../styles/colors";
import { useAtom } from "jotai";
import { currentUserId, currentUserRole } from "../../atoms/currentUser";
import { ReviewTaskTypeEnum } from "../../../server/types/enums";
import LargeDrawer from "../LargeDrawer";
import SentenceReportPreview from "./SentenceReportPreview";
import { useAppSelector } from "../../store/store";
import ClaimReviewHeader from "../ClaimReview/ClaimReviewHeader";
import { Content } from "../../types/Content";
interface ISentenceReportViewV1Props {
context: any;
userIsNotRegular: boolean;
userIsReviewer: boolean;
isHidden: boolean;
href: string;
componentStyle: any;
personality?: any;
content: Content;
target?: any;
hideDescriptions?: any;
}
const SentenceReportPreviewView = ({
context,
userIsNotRegular,
userIsReviewer,
isHidden,
href,
componentStyle,
personality,
content,
target,
hideDescriptions,
}: ISentenceReportViewV1Props) => {
const { reviewDrawerCollapsed } = useAppSelector((state) => ({
reviewDrawerCollapsed:
state?.reviewDrawerCollapsed !== undefined
? state?.reviewDrawerCollapsed
: true,
}));
const [role] = useAtom(currentUserRole);
const [userId] = useAtom(currentUserId);
const {
machineService,
publishedReview,
reviewTaskType,
viewPreview,
handleClickViewPreview,
} = useContext(ReviewTaskMachineContext);
const isReport = useSelector(machineService, reportSelector);
const isCrossChecking = useSelector(machineService, crossCheckingSelector);
const isAssigned = useSelector(machineService, assignedSelector);
const isReviewing = useSelector(machineService, reviewingSelector);
const isPublished =
useSelector(machineService, publishedSelector) ||
publishedReview?.review;
const userIsAdmin = role === Roles.Admin || role === Roles.SuperAdmin;
const userIsCrossChecker = context.crossCheckerId === userId;
const userIsAssignee = context.usersId.includes(userId);
const isCrossCheckingAndUserHasPermission =
isCrossChecking && (userIsAdmin || userIsCrossChecker);
const isReviewingAndUserHasPermission =
isReviewing && (userIsAdmin || userIsReviewer);
const isAssignedAndUserHasPermission =
isAssigned && (userIsAdmin || userIsAssignee || userIsCrossChecker);
const isReportedAndUserHasPermission =
isReport && (userIsAdmin || userIsAssignee || userIsCrossChecker);
const canShowReportPreview =
isCrossCheckingAndUserHasPermission ||
isReviewingAndUserHasPermission ||
isReportedAndUserHasPermission ||
isAssignedAndUserHasPermission;
const canShowReport =
(isPublished && (!isHidden || userIsNotRegular)) ||
(canShowReportPreview && viewPreview && !reviewDrawerCollapsed);
return (
reviewTaskType !== ReviewTaskTypeEnum.VerificationRequest && (
<Grid container
justifyContent="center"
style={
(isCrossChecking || isReport || isReviewing)
? { backgroundColor: colors.error }
: undefined
}
>
{canShowReport && (
<SentenceReportPreview
canShowReportPreview={canShowReportPreview}
context={context}
href={href}
componentStyle={componentStyle}
/>
)}
{reviewDrawerCollapsed && (
<LargeDrawer
onClose={handleClickViewPreview}
open={viewPreview}
>
<Grid item
style={{
height: "100%",
display: "flex",
flexDirection: "column",
gap: 32,
}}
>
<ClaimReviewHeader
classification={context.classification}
userIsNotRegular={userIsNotRegular}
personality={personality}
content={content}
hideDescription={hideDescriptions}
target={target}
componentStyle={{
span: 10,
}}
/>
<SentenceReportPreview
canShowReportPreview={canShowReportPreview}
context={context}
href={href}
componentStyle={{
span: 10,
}}
/>
</Grid>
</LargeDrawer>
)}
</Grid>
)
);
};
export default SentenceReportPreviewView;