-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functionality for course_admins to make projects visible to stu…
…dents after a chosen timestamp
- Loading branch information
1 parent
19ef550
commit 23300f3
Showing
6 changed files
with
145 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 85 additions & 51 deletions
136
frontend/src/components/forms/projectFormTabs/GeneralFormTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,93 @@ | ||
import { DatePicker, Form, FormInstance, Input, Switch, Typography } from "antd" | ||
import { useTranslation } from "react-i18next" | ||
import { FC } from "react" | ||
import { FC, useEffect, useState } from "react" | ||
import MarkdownEditor from "../../input/MarkdownEditor" | ||
|
||
const GeneralFormTab: FC<{ form: FormInstance }> = ({ form }) => { | ||
const { t } = useTranslation() | ||
const description = Form.useWatch("description", form) | ||
|
||
return ( | ||
<> | ||
<Form.Item | ||
label={t("project.change.name")} | ||
name="name" | ||
rules={[{ required: true, message: t("project.change.nameMessage") }]} | ||
> | ||
<Input /> | ||
</Form.Item> | ||
|
||
<Typography.Text> | ||
{t("project.change.description")} | ||
</Typography.Text> | ||
<MarkdownEditor value={description} maxLength={5000} /> | ||
|
||
<Form.Item | ||
label={t("project.change.visible")} | ||
required | ||
name="visible" | ||
valuePropName="checked" | ||
> | ||
<Switch /> | ||
</Form.Item> | ||
<Form.Item | ||
label={t("project.change.maxScore")} | ||
name="maxScore" | ||
tooltip={t("project.change.maxScoreHelp")} | ||
rules={[{ required: false, message: t("project.change.maxScoreMessage") }]} | ||
> | ||
<Input | ||
min={1} | ||
max={1000} | ||
type="number" | ||
/> | ||
</Form.Item> | ||
<Form.Item | ||
label={t("project.change.deadline")} | ||
name="deadline" | ||
rules={[{ required: true }]} | ||
> | ||
<DatePicker | ||
showTime | ||
format="YYYY-MM-DD HH:mm:ss" | ||
/> | ||
</Form.Item> | ||
</> | ||
) | ||
const { t } = useTranslation() | ||
const description = Form.useWatch("description", form) | ||
const visible = Form.useWatch("visible", form) | ||
const [isVisible, setIsVisible] = useState(visible) | ||
const [savedVisibleAfter, setSavedVisibleAfter] = useState<string | null>(null) | ||
|
||
useEffect(() => { | ||
setIsVisible(visible) | ||
if (visible && savedVisibleAfter) { | ||
form.setFieldsValue({ visibleAfter: null }) | ||
} | ||
}, [visible]) | ||
|
||
const handleVisibleChange = (checked: boolean) => { | ||
setIsVisible(checked) | ||
if (checked) { | ||
setSavedVisibleAfter(form.getFieldValue("visibleAfter")) | ||
form.setFieldsValue({ visibleAfter: null }) | ||
} else { | ||
form.setFieldsValue({ visibleAfter: savedVisibleAfter }) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<Form.Item | ||
label={t("project.change.name")} | ||
name="name" | ||
rules={[{ required: true, message: t("project.change.nameMessage") }]} | ||
> | ||
<Input /> | ||
</Form.Item> | ||
|
||
<Typography.Text> | ||
{t("project.change.description")} | ||
</Typography.Text> | ||
<MarkdownEditor value={description} maxLength={5000} /> | ||
|
||
<Form.Item | ||
label={t("project.change.visible")} | ||
required | ||
name="visible" | ||
valuePropName="checked" | ||
> | ||
<Switch onChange={handleVisibleChange} /> | ||
</Form.Item> | ||
|
||
{!isVisible && ( | ||
<Form.Item | ||
label={t("project.change.visibleAfter")} | ||
name="visibleAfter" | ||
> | ||
<DatePicker | ||
showTime | ||
format="YYYY-MM-DD HH:mm:ss" | ||
/> | ||
</Form.Item> | ||
)} | ||
|
||
<Form.Item | ||
label={t("project.change.maxScore")} | ||
name="maxScore" | ||
tooltip={t("project.change.maxScoreHelp")} | ||
rules={[{ required: false, message: t("project.change.maxScoreMessage") }]} | ||
> | ||
<Input | ||
min={1} | ||
max={1000} | ||
type="number" | ||
/> | ||
</Form.Item> | ||
|
||
<Form.Item | ||
label={t("project.change.deadline")} | ||
name="deadline" | ||
rules={[{ required: true }]} | ||
> | ||
<DatePicker | ||
showTime | ||
format="YYYY-MM-DD HH:mm:ss" | ||
/> | ||
</Form.Item> | ||
</> | ||
) | ||
} | ||
|
||
export default GeneralFormTab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters