Newer
Older
import React, { Component } from 'react';
import { connect } from 'react-redux';
const allowedFileTypes = [
'image/jpeg',
'image/png',
'application/zip',
'application/x-zip',
class AddSolutionForm extends Component {
constructor(props) {
super(props);
this.state = {
showModal: false,
const { name, description, file } = this.props.newSolution;
const thisTaskSolution = this.props.homeworks.solutions.filter(
(solution) => solution.task === task
);
const thisTaskDocument = this.props.homeworks.documents.filter(
(document) => document.solution === thisTaskSolution[0]?.id
);
const lastName = thisTaskDocument[0]?.name;
const lastDesc = thisTaskDocument[0]?.description;
const lastFile = thisTaskDocument[0]?.file_url;
const corrected = false;
const accepted = false;
const sentences = this.props.taskdesc.split('\n');
const disabledText = 'A határidő lejárt, további beadás nem lehetséges.';
return (
<Modal
open={this.state.showModal}
closeOnDimmerClick
onClose={() => this.setState({ showModal: false })}
this.setState({ showModal: true });
}}
{this.props.multiple ? 'Másik megoldás' : 'Megoldás'} beadása a(z)
{this.props.tasktitle} nevű feladathoz:
<Modal.Description style={{ marginBottom: '2em' }}>
<Header as="h5">Feladat leírása:</Header>
{sentences.map((s) => (
<p key={Math.random()}>{s}</p>
))}
</Modal.Description>
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
{this.props.disabled ? (
<div>
{lastName ? (
<div style={{ paddingBottom: '1em' }}>
<div style={{ marginBottom: '1em', fontWeight: 'bold' }}>
Legutóbbi megoldásod:
</div>
<Segment attached="top">
<h5 style={{ paddingBottom: '0.4em' }}>Cím:</h5>
{lastName}
</Segment>
<Segment attached>
<h5 style={{ paddingBottom: '0.4em' }}>Leírás:</h5>
{lastDesc}
</Segment>
<Segment attached="bottom">
<h5>Beadott fájl:</h5>
{lastFile ? (
<a href={lastFile} rel="noreferrer noopener" download>
Fájl letöltése
</a>
) : (
<span>-</span>
)}
</Segment>
</div>
) : (
customMessage(
disabledText,
undefined,
undefined,
this.props.disabled
)
)}
</div>
) : (
<Form>
{lastName ? (
<div style={{ paddingBottom: '1em' }}>
<div style={{ fontWeight: 'bold' }}>
Legutóbbi megoldásod:
</div>
<Segment attached="top">
<h5 style={{ paddingBottom: '0.4em' }}>Cím:</h5>
{lastName}
</Segment>
<Segment attached>
<h5 style={{ paddingBottom: '0.4em' }}>Leírás:</h5>
{lastDesc}
</Segment>
<Segment attached="bottom">
<h5>Beadott fájl:</h5>
{lastFile ? (
<a href={lastFile} rel="noreferrer noopener" download>
Fájl letöltése
</a>
) : (
<span>-</span>
)}
</Segment>
</div>
) : null}
<Divider />
<Form.Field
control={Input}
label="Megoldás címe:"
name="name"
onChange={(e) => this.props.writeSolution(e)}
value={name}
placeholder="Adj meg egy címet a beadandó megoldásodnak..."
/>
<Form.Field
control={TextArea}
label="Megoldás leírása:"
name="description"
onChange={(e) => this.props.writeSolution(e)}
value={description}
placeholder="Add meg a megoldás leírását..."
/>
<Form.Field>
<label>
Fájl (Megengedett fájltípusok: png, jpeg, jpg, zip. Maximum 50
MB.):
</label>
<Input
type="file"
</Modal.Content>
<Modal.Actions>
<Button
inverted
onClick={() => {
this.setState({ showModal: false });
this.props.clearWrite();
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
{this.props.multiple ? (
<ConfirmModal
button={
<Button
disabled={
!name ||
!description ||
(!file
? false
: !allowedFileTypes.includes(file.type) ||
file.size > maxFileSize * 1024 ** 2)
}
inverted
color="green"
>
<Icon name="checkmark" />
Beadás
{this.state.loading ? (
<Dimmer active>
<Loader size="massive" />
</Dimmer>
) : null}
</Button>
}
text="beadod az új megoldást, ami felülírja az előzőt"
onAccept={() => {
this.setState({
loading: true,
});
this.props
.addSolution({
task,
accepted,
corrected,
note,
name,
description,
file,
})
.then(
() => {
this.setState({
loading: false,
showModal: false,
});
this.props.clearWrite();
},
() => {
this.setState({
loading: false,
});
alert('Sikertelen feltöltés!');
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
286
287
288
289
);
}}
/>
) : (
<Button
inverted
color="green"
disabled={
!name ||
!description ||
(!file
? false
: !allowedFileTypes.includes(file.type) ||
file.size > maxFileSize * 1024 ** 2)
}
onClick={() => {
this.props.addSolution({
task,
accepted,
corrected,
note,
name,
description,
file,
});
this.setState({ showModal: false });
this.props.clearWrite();
}}
>
<Icon name="checkmark" /> Beadás
</Button>
)}
</Modal.Actions>
</Modal>
);
}
}
const mapStateToProps = ({ newSolution, homeworks, user }) => ({
newSolution,
homeworks,
user,
});
export default connect(mapStateToProps, {
addSolution,
writeSolution,
writeSolutionFile,
addDocument,