-
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.
aggiunta view personalizzata per corsi di dottorato ed altre lievi mo…
…difiche
- Loading branch information
Showing
7 changed files
with
554 additions
and
149 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { Button, Table } from 'react-bootstrap' | ||
|
||
import * as Icon from 'react-bootstrap-icons' | ||
import { Link } from 'react-router-dom'; | ||
import { useEngine } from '../Engine'; | ||
import Loading from './Loading'; | ||
|
||
/** @typedef {import('../models/EventPhdCourse').Lesson} Lesson */ | ||
|
||
/** | ||
* Formats a UTC date to "YYYY-MM-DD HH:mm" | ||
* @type {(date: string | Date) => string} | ||
*/ | ||
const formatDate = (date) => { | ||
if (typeof date === 'string') date = new Date(date) | ||
|
||
const year = date.getFullYear(); | ||
const month = (date.getMonth() + 1).toString().padStart(2, '0'); | ||
const day = date.getDate().toString().padStart(2, '0'); | ||
const hours = date.getHours().toString().padStart(2, '0'); | ||
const minutes = date.getMinutes().toString().padStart(2, '0'); | ||
|
||
const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}`; | ||
|
||
return formattedDate; | ||
} | ||
|
||
export const isValidDate = (dateString) => { | ||
try { | ||
parseDate(dateString) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
} | ||
|
||
export const parseDate = (dateString) => { | ||
const [datePart, timePart] = dateString.trim().split(/\s+/g) | ||
const [year, month, day] = datePart.split('-') | ||
const [hours, minutes] = timePart.split(':') | ||
|
||
console.log(year, month, day, hours, minutes) | ||
|
||
if (year === undefined || month === undefined || day === undefined || hours === undefined || minutes === undefined) { | ||
throw new Error('invalid date format, expected "YYYY-MM-DD HH:mm"') | ||
} | ||
|
||
const utcDate = new Date( | ||
parseInt(year, 10), | ||
parseInt(month, 10) - 1, // Months are zero-based | ||
parseInt(day, 10), | ||
parseInt(hours, 10), | ||
parseInt(minutes, 10) | ||
) | ||
|
||
return utcDate | ||
} | ||
|
||
/** | ||
* @param {{ lessons: Lesson[], deleteLesson: (index: number) => void }} props | ||
*/ | ||
export const LessonTable = ({ lessons, deleteLesson }) => { | ||
const isEdit = !!deleteLesson | ||
|
||
const Room = ({ id }) => { | ||
const engine = useEngine() | ||
const { isSuccess, data } = engine.useGet('room', id) | ||
|
||
if (!isSuccess) return <Loading /> | ||
const { Room } = engine.Models | ||
return <Link key={data._id} to={Room.viewUrl(data._id)}>{Room.describe(data)}</Link> | ||
} | ||
|
||
return ( | ||
<Table className="align-middle"> | ||
<thead className="thead-dark"> | ||
<tr> | ||
<th>Orario</th> | ||
<th>Durata (minuti)</th> | ||
<th>Stanza</th> | ||
{isEdit && <th></th>} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{lessons.map((lesson, i) => ( | ||
<tr key={i}> | ||
<td>{formatDate(lesson.date)}</td> | ||
<td>{lesson.duration}</td> | ||
<td> | ||
{typeof lesson.room !== 'string' | ||
? lesson.room.code | ||
: <Room id={lesson.room} />} | ||
</td> | ||
{isEdit && ( | ||
<td> | ||
<Button | ||
className="btn btn-danger btn-sm" | ||
onClick={() => deleteLesson(i)}> | ||
<Icon.Trash /> | ||
</Button> | ||
</td> | ||
)} | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
) | ||
} |
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
Oops, something went wrong.