generated from openedx/frontend-template-application
-
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.
- Loading branch information
Showing
14 changed files
with
371 additions
and
14 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
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
59 changes: 59 additions & 0 deletions
59
src/features/Dashboard/WeeklySchedule/_test_/index.test.jsx
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,59 @@ | ||
import React from 'react'; | ||
import WeeklySchedule from 'features/Dashboard/WeeklySchedule'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { renderWithProviders } from 'test-utils'; | ||
|
||
jest.mock('@edx/frontend-platform/logging', () => ({ | ||
logError: jest.fn(), | ||
})); | ||
|
||
describe('WeeklySchedule component', () => { | ||
const mockStore = { | ||
dashboard: { | ||
classes: { | ||
data: [ | ||
{ | ||
classId: 'ccx-v1:demo+demo1+2020+ccx1', | ||
className: 'ccx 1', | ||
masterCourseName: 'Demo Course 1', | ||
instructors: [ | ||
'instructor1', | ||
], | ||
numberOfStudents: 0, | ||
numberOfPendingStudents: 0, | ||
maxStudents: 20, | ||
startDate: '2024-01-23T21:50:51Z', | ||
endDate: null, | ||
}, | ||
{ | ||
classId: 'ccx-v1:demo+demo1+2020+ccx2', | ||
className: 'ccx 2', | ||
masterCourseName: 'Demo Course 1', | ||
instructors: [ | ||
'instructor1', | ||
], | ||
numberOfStudents: 0, | ||
numberOfPendingStudents: 0, | ||
maxStudents: 20, | ||
startDate: '2023-10-02T12:58:43Z', | ||
endDate: null, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
const component = renderWithProviders( | ||
<WeeklySchedule />, | ||
{ preloadedState: mockStore }, | ||
); | ||
|
||
test('renders components', () => { | ||
const { getByText } = component; | ||
|
||
expect(getByText('Class schedule')).toBeInTheDocument(); | ||
expect(getByText('ccx 1')).toBeInTheDocument(); | ||
expect(getByText('Jan 23, 2024')).toBeInTheDocument(); | ||
expect(getByText('ccx 2')).toBeInTheDocument(); | ||
expect(getByText('Oct 2, 2023')).toBeInTheDocument(); | ||
}); | ||
}); |
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,79 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
|
||
import { DateRange } from 'react-date-range'; | ||
import { | ||
startOfWeek, | ||
endOfWeek, | ||
format, | ||
} from 'date-fns'; | ||
|
||
import { fetchClassesData } from 'features/Dashboard/data'; | ||
|
||
import 'features/Dashboard/WeeklySchedule/index.scss'; | ||
|
||
const WeeklySchedule = () => { | ||
const dispatch = useDispatch(); | ||
const selectedInstitution = useSelector((state) => state.main.selectedInstitution); | ||
const classesData = useSelector((state) => state.dashboard.classes.data); | ||
const [classList, setClassList] = useState([]); | ||
const startWeek = startOfWeek(new Date()); | ||
const endWeek = endOfWeek(new Date()); | ||
const [stateDate, setStateDate] = useState([ | ||
{ | ||
startDate: startWeek, | ||
endDate: endWeek, | ||
key: 'selection', | ||
}, | ||
]); | ||
const numberOfClasses = 3; | ||
|
||
useEffect(() => { | ||
if (Object.keys(selectedInstitution).length > 0) { | ||
dispatch(fetchClassesData(selectedInstitution?.id, true)); | ||
} | ||
}, [selectedInstitution, dispatch]); | ||
|
||
useEffect(() => { | ||
// Display only the first 'NumberOfClasses' on the homepage. | ||
if (classesData.length > numberOfClasses) { | ||
setClassList(classesData.slice(0, numberOfClasses)); | ||
} else { | ||
setClassList(classesData); | ||
} | ||
}, [classesData]); | ||
|
||
return ( | ||
<> | ||
<div className="header-schedule"> | ||
<h3>Class schedule</h3> | ||
</div> | ||
<div className="content-schedule d-flex justify-content-between"> | ||
<div className="container-class-schedule"> | ||
{classList.map(classInfo => { | ||
const date = format(new Date(classInfo?.startDate), 'PP'); | ||
return ( | ||
<div className="class-schedule" key={classInfo?.classId}> | ||
<div className="class-text"> | ||
<p className="class-name">{classInfo?.className}</p> | ||
<p className="class-descr"> | ||
<i className="fa-sharp fa-regular fa-calendar-day" />{date} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
<DateRange | ||
showDateDisplay={false} | ||
onChange={item => setStateDate([item.selection])} | ||
moveRangeOnFirstSelection={false} | ||
ranges={stateDate} | ||
rangeColors={['#e4faff']} | ||
/> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default WeeklySchedule; |
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,87 @@ | ||
@import "assets/colors.scss"; | ||
|
||
.header-schedule { | ||
background-color: $primary; | ||
padding: 1rem; | ||
border-top-right-radius: 0.375rem; | ||
border-top-left-radius: 0.375rem; | ||
|
||
h3 { | ||
color: $color-white; | ||
margin: 0; | ||
} | ||
} | ||
|
||
.content-schedule { | ||
box-shadow: 0px 3px 12px 0px rgba(0, 0, 0, 0.16); | ||
border-radius: 0.375rem; | ||
|
||
.rdrDay:not(.rdrDayPassive) .rdrInRange ~ .rdrDayNumber span, | ||
.rdrDay:not(.rdrDayPassive) .rdrStartEdge ~ .rdrDayNumber span, | ||
.rdrDay:not(.rdrDayPassive) .rdrEndEdge ~ .rdrDayNumber span, | ||
.rdrDay:not(.rdrDayPassive) .rdrSelected ~ .rdrDayNumber span { | ||
color: $primary; | ||
} | ||
|
||
.rdrStartEdge { | ||
border-top: 1px solid $primary; | ||
border-left: 1px solid $primary; | ||
border-bottom: 1px solid $primary; | ||
} | ||
|
||
.rdrInRange { | ||
border-top: 1px solid $primary; | ||
border-bottom: 1px solid $primary; | ||
} | ||
|
||
.rdrEndEdge { | ||
border-top: 1px solid $primary; | ||
border-right : 1px solid $primary; | ||
border-bottom: 1px solid $primary; | ||
} | ||
|
||
.rdrCalendarWrapper { | ||
border-radius: 0.375rem; | ||
} | ||
|
||
.rdrMonthAndYearPickers select, | ||
.rdrMonthAndYearPickers select { | ||
font-weight: 700; | ||
} | ||
} | ||
|
||
.container-class-schedule { | ||
width: 100%; | ||
background: $color-white; | ||
padding: 0.8rem; | ||
border-radius: 0.375rem; | ||
border-right: 1px solid $gray-20; | ||
|
||
.class-schedule { | ||
margin-top: 0.5rem; | ||
border-bottom: 1px solid $gray-20; | ||
|
||
.class-name { | ||
margin: 0; | ||
font-weight: 600; | ||
color: $primary; | ||
} | ||
|
||
.class-descr { | ||
margin: 0; | ||
font-size: 12px; | ||
} | ||
|
||
.fa-calendar-day { | ||
margin-right: 8px; | ||
} | ||
} | ||
|
||
.class-text { | ||
border-left: 3px solid $primary; | ||
padding-left: 1rem; | ||
padding-left: 1rem; | ||
margin-bottom: 1rem; | ||
padding-bottom: 0.5rem; | ||
} | ||
} |
Oops, something went wrong.