Skip to content

Commit

Permalink
added public/private checkbox and private date
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwaqaljanahi2021 committed Nov 5, 2024
1 parent 74a59a2 commit 38853eb
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 20 deletions.
4 changes: 4 additions & 0 deletions devU-api/src/entities/course/course.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ export default class CourseModel {

@Column({ type: 'boolean', name: 'is_public', default: false })
isPublic: boolean;

@Column({ name: 'private_data', type: 'timestamp', default: () => 'now()' })
private_data?: Date;

}
3 changes: 2 additions & 1 deletion devU-api/src/entities/course/course.serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function serialize(course: CourseModel): Course {
endDate: course.endDate.toISOString(),
createdAt: course.createdAt.toISOString(),
updatedAt: course.updatedAt.toISOString(),
isPublic: course.isPublic
isPublic: course.isPublic,
private_data: course.private_data ? course.private_data.toISOString() : undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class addAssignmentsAndCourses1626719306608 implements MigrationInterface
"updated_at" TIMESTAMP NOT NULL DEFAULT now(),
"deleted_at" TIMESTAMP,
"is_public" boolean NOT NULL DEFAULT false,
"private_data" TIMESTAMP NOT NULL DEFAULT now(),
CONSTRAINT "courses_primary_key_constraint" PRIMARY KEY ("id")
)`
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ const CourseUpdatePage = ({ }) => {
name: '',
number: '',
semester: '',
isPublic: false
})
const [startDate, setStartDate] = useState(new Date().toISOString())
const [endDate, setEndDate] = useState(new Date().toISOString())
const [studentEmail, setStudentEmail] = useState("")
const [emails, setEmails] = useState<string[]>([])
const [invalidFields, setInvalidFields] = useState(new Map<string, string>())
const [privateDate, setPrivateDate] = useState(new Date().toISOString().split("T")[0]);

const { courseId } = useParams() as UrlParams
useEffect(() => {
Expand All @@ -60,9 +62,11 @@ const CourseUpdatePage = ({ }) => {
name: res.name,
number: res.number,
semester: res.semester,
isPublic: res.isPublic
});
setStartDate(new Date(res.startDate).toISOString().split("T")[0]);
setEndDate(new Date(res.endDate).toISOString().split("T")[0]);
setPrivateDate(new Date(res.privateDate).toISOString().split("T")[0]);
isMounted = true;
});
}
Expand All @@ -80,17 +84,24 @@ const CourseUpdatePage = ({ }) => {
setFormData(prevState => ({ ...prevState, [key]: value }))
}
}

const handleCheckboxChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFormData(prevState => ({ ...prevState, isPublic: e.target.checked }));
};
const handleStartDateChange = (event: React.ChangeEvent<HTMLInputElement>) => { setStartDate(event.target.value) }
const handleEndDateChange = (event: React.ChangeEvent<HTMLInputElement>) => { setEndDate(event.target.value) }

const handlePrivateDateChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setPrivateDate(event.target.value);
};
const handleCourseUpdate = () => {
const finalFormData = {
name: formData.name,
number: formData.number,
semester: formData.semester,
startDate: startDate + "T16:02:41.849Z",
endDate: endDate + "T16:02:41.849Z",
isPublic: formData.isPublic,
privateDate: privateDate + "T16:02:41.849Z",
}

RequestService.put(`/api/courses/${courseId}`, finalFormData)
Expand Down Expand Up @@ -267,6 +278,20 @@ const CourseUpdatePage = ({ }) => {
<label htmlFor='end-date'>End Date *</label>
<input type="date" id="end-date" value={endDate} onChange={handleEndDateChange} />
</div>
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', flexDirection: 'column', gap: '5px' }}>
<label htmlFor='private-date'>Private Date *</label>
<input type="date" id="private-date" value={privateDate} onChange={handlePrivateDateChange} />
</div>
<div>
<label>
<input
type="checkbox"
checked={formData.isPublic}
onChange={handleCheckboxChange}
/>
Make this course public
</label>
</div>
</div>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<button className='btnPrimary' onClick={handleCourseUpdate}>Update Course</button>
Expand Down
16 changes: 13 additions & 3 deletions devU-client/src/components/pages/forms/courses/coursesFormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ const EditCourseFormPage = () => {

const [startDate, setStartDate] = useState(new Date().toISOString().split("T")[0]);
const [endDate, setEndDate] = useState(new Date().toISOString().split("T")[0]);
const [privateDate, setPrivateDate] = useState(new Date().toISOString().split("T")[0]);

const handleChange = (value: string, e: React.ChangeEvent<HTMLInputElement>) => {
const key = e.target.id;
setFormData(prevState => ({ ...prevState, [key]: value }));
};

const handleCheckboxChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFormData(prevState => ({ ...prevState, isPublic: e.target.checked })); // Change to isPublic
setFormData(prevState => ({ ...prevState, isPublic: e.target.checked }));
};

const handleStartDateChange = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -38,6 +39,10 @@ const EditCourseFormPage = () => {
setEndDate(event.target.value);
};

const handlePrivateDateChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setPrivateDate(event.target.value);
};

const formatDateForSubmission = (date: string) => {
return new Date(date).toISOString();
};
Expand All @@ -53,7 +58,8 @@ const EditCourseFormPage = () => {
semester: formData.semester,
startDate: formatDateForSubmission(startDate),
endDate: formatDateForSubmission(endDate),
isPublic: formData.isPublic
isPublic: formData.isPublic,
privateDate: formatDateForSubmission(privateDate)
};

RequestService.post('/api/courses/instructor', finalFormData)
Expand Down Expand Up @@ -98,12 +104,16 @@ const EditCourseFormPage = () => {
<label htmlFor='end-date'>End Date *</label>
<input type="date" id="end-date" value={endDate} onChange={handleEndDateChange} />
</div>
<div>
<label htmlFor='private-date'>Private Date *</label>
<input type="date" id="private-date" value={privateDate} onChange={handlePrivateDateChange} />
</div>
</div>
<div>
<label>
<input
type="checkbox"
checked={formData.isPublic} // Reflect isPublic
checked={formData.isPublic}
onChange={handleCheckboxChange}
/>
Make this course public
Expand Down
2 changes: 1 addition & 1 deletion devU-shared/src/types/course.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type Course = {
createdAt?: string
updatedAt?: string
isPublic?: boolean;
makePrivateDate?: string;
private_data?: string;
allowlist?: string[];
blocklist?: string[];
}

0 comments on commit 38853eb

Please sign in to comment.