-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathRemoveTestimony.tsx
More file actions
183 lines (174 loc) · 4.93 KB
/
RemoveTestimony.tsx
File metadata and controls
183 lines (174 loc) · 4.93 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
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
import { Card, CardContent, CardHeader, Stack } from "@mui/material"
import { deleteTestimony } from "components/api/delete-testimony"
import { resolveReport } from "components/db"
import { getAuth } from "firebase/auth"
import { Timestamp } from "functions/src/firebase"
import { FormEventHandler, useState } from "react"
import { useRedirect, useNotify, useRefresh } from "react-admin"
import { Report, Resolution } from "."
export type ReportResponseValues = {
reportId: string
resolution: Resolution
reason: string
}
export const onSubmitReport = async (
reportId: string,
resolution: Resolution,
reason: string,
authorUid: string,
publicationId: string,
refresh: () => void
) => {
const r = await resolveReport({
reportId,
resolution,
reason
})
if (r.data.status !== `success`) {
alert(r.data.status)
}
if (resolution === "remove-testimony") {
// If removing testimony, call deleteTestimony to move testimony from 'published' to 'archived'
await deleteTestimony(authorUid, publicationId)
}
refresh()
}
export function RemoveTestimonyForm({ report }: { report: Report }) {
const [resolution, setResolution] = useState<Resolution | undefined>(
report.resolution?.resolution
)
const [reason, setReason] = useState<string | undefined>(
report.resolution?.reason
)
const redirect = useRedirect()
const auth = getAuth()
const refresh = useRefresh()
const reportResolved = report.resolution?.resolution !== undefined
const onSubmit: FormEventHandler<HTMLFormElement> = async e => {
e.preventDefault()
if (resolution && reason && report.id) {
await onSubmitReport(
report.id,
resolution,
reason,
report.authorUid,
report.testimonyId,
refresh
)
redirect("list", "reports")
} else {
console.log("one of these not defined", resolution, reason, report.id)
}
}
return (
<form onSubmit={onSubmit}>
<Card>
<CardHeader
title={"Resolve Report"}
subheader={`Report id: ${report.id}`}
/>
{reportResolved && (
<CardContent>
<div>
Resolved by:
{auth?.currentUser?.email}
</div>
<div>
Resolved on:{" "}
{(report.resolution?.resolvedAt as Timestamp)
.toDate()
.toLocaleDateString()}
</div>
</CardContent>
)}
<CardContent
sx={{
width: "100%",
display: "flex",
justifyContent: "flex-start"
}}
>
<Stack
flex={1}
border={"1px solid lightgray"}
borderRadius={"10px"}
gap={1}
padding={2}
margin={1}
>
Resolution:
<Stack direction={"column"}>
<label htmlFor="resolveReportRemove">
<input
disabled={reportResolved}
style={{ margin: "1em" }}
type="radio"
value="remove-testimony"
id="resolveReportRemove"
onChange={() => {
setResolution("remove-testimony")
}}
checked={resolution === "remove-testimony"}
/>
Remove
</label>
<label htmlFor="resolveReportAllow">
<input
disabled={reportResolved}
style={{ margin: "1em" }}
type="radio"
onChange={() => {
setResolution("allow-testimony")
}}
id="resolveReportAllow"
value="allow-testimony"
checked={resolution === "allow-testimony"}
/>
Allow
</label>
</Stack>
</Stack>
<Stack
flex={2}
border={"1px solid lightgray"}
borderRadius={"10px"}
gap={1}
padding={2}
margin={1}
>
<label htmlFor="resolveReportComment">Reason:</label>
<textarea
disabled={reportResolved}
style={{
flex: "1"
}}
rows={3}
required
id="resolveReportComment"
onChange={e => {
setReason(e.target.value)
}}
value={reason}
/>
</Stack>
</CardContent>
<CardContent>
<div
style={{
display: "flex",
flexDirection: "column",
margin: "1em",
flex: 0
}}
>
<input
style={{ margin: "auto" }}
type="submit"
disabled={reportResolved}
/>
</div>
</CardContent>
</Card>
</form>
)
}