[go: nahoru, domu]

Skip to content

Commit

Permalink
(Task #2): Add additional functionality for not attending attendance …
Browse files Browse the repository at this point in the history
…form
  • Loading branch information
MirTalpur committed May 7, 2020
1 parent 350778f commit 6b0a03f
Show file tree
Hide file tree
Showing 3 changed files with 509 additions and 118 deletions.
199 changes: 199 additions & 0 deletions components/attendanceComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import React from 'react';
import { Layout, Menu, Breadcrumb } from 'antd';
import { DatePicker } from 'antd';
const { RangePicker } = DatePicker;
import { Form, TimePicker, Button, Tooltip, Input, Row, Col, Card, Avatar, Space, Switch, Alert } from 'antd';
const { Meta } = Card;

import { CalendarOutlined } from '@ant-design/icons';

import stylesheet from 'antd/dist/antd.min.css';

export default class AttendanceComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
dates: null,
setDates: null,
formItemLayout: {
labelCol: {
xs: {
span: 24,
},
sm: {
span: 8,
},
},
wrapperCol: {
xs: {
span: 24,
},
sm: {
span: 16,
},
},
},
}
}

componentDidMount() {
console.log("in attendance component class....");
}

disabledDate = current => {
if (!this.state.dates || this.state.dates.length === 0) {
return false;
}
const tooLate = this.state.dates[0] && current.diff(this.state.dates[0], 'days') > 7;
const tooEarly = this.state.dates[1] && this.state.dates[1].diff(current, 'days') > 7;
return tooEarly || tooLate;
};

reasonComponent = () => {
if(this.props.attendanceComponent.clientSideValidationErrors.studentAttendanceReasonsValidationError != null){
if(this.props.attendanceComponent.studentAttendanceOtherReasonShow){
return(
<Form.Item
validateStatus="error"
help="Please select a reason">
<Input size="medium"
onChange={(event)=>this.props.handleStudentAttendanceOtherReasonInput(event)}
/>
</Form.Item>
)
} else {
return(
<div>
<Form.Item
validateStatus="error"
help="Please select a reason">
<Space>
<Button type="primary" size="large"
onClick={(e) => this.props.studentAttendanceSickClicked(e)}
>
Sick
</Button>
<Button size="large"
onClick={(e) => this.props.studentAttendanceOtherReasonClicked(e)}
>
Other
</Button>
</Space>
</Form.Item>
</div>
)
}
} else {
if(this.props.attendanceComponent.studentAttendanceOtherReasonShow){
return(
<Form.Item>
<Input size="medium"
onChange={(event)=>this.props.handleStudentAttendanceOtherReasonInput(event)}
/>
</Form.Item>
)
} else {
return(
<div>
<Space>
<Button type="primary" size="large"
onClick={(e) => this.props.studentAttendanceSickClicked(e)}
>
Sick
</Button>
<Button size="large"
onClick={(e) => this.props.studentAttendanceOtherReasonClicked(e)}
>
Other
</Button>
</Space>
</div>
)
}
}
}

switchComponent = () => {
return(
<Switch style={{ float: 'right' }} onChange={(e) => this.props.markAllStudentAtendanceTheSame(e)} />
)
}

showValidationErrorAlertForNotAttendingComponent = () => {
if(this.props.attendanceComponent.clientSideValidationErrors.noStudentSelectedValidationError == true){
return(
<div>
<Alert message="No Students selected please pick all students or a student from the sidebar" type="error" />
</div>
)
}
}

notAttendingFormSubmitButton = () => {
if(this.props.attendanceComponent.notAttendingSubmitButtonLoading == true){
return(
<Button type="primary" size="large"
onClick={(e) => this.props.studentAttendanceSubmitClicked(e)}
style={{ float: 'right' }}
loading
>
Submit
</Button>
)
} else {
return(
<Button type="primary" size="large"
onClick={(e) => this.props.studentAttendanceSubmitClicked(e)}
style={{ float: 'right' }}
>
Submit
</Button>
)
}
}

render() {
return (
<React.Fragment>
<style dangerouslySetInnerHTML={{ __html: stylesheet }} />
<Card title="Not Attending" style={{ width: 350 }}>
<Form name="time_related_controls" >
{this.showValidationErrorAlertForNotAttendingComponent()}
Day
{
this.props.attendanceComponent.clientSideValidationErrors.rangePickerAttendanceValidationError ?
<Form.Item name="range-picker"
validateStatus="error"
help="Please select a date"
>
<br/>
<RangePicker
disabledDate={this.disabledDate}
onCalendarChange={(dates, dateString) => {this.props.handleStudentAttendanceDateRange(dates, dateString)}}
size="large"
/>
</Form.Item>
:
<Form.Item name="range-picker">
<br/>
<RangePicker
disabledDate={this.disabledDate}
onCalendarChange={(dates, dateString) => {this.props.handleStudentAttendanceDateRange(dates, dateString)}}
size="large"
/>
</Form.Item>
}
Reason
{this.reasonComponent()}
<br/>
For All Students
{this.switchComponent()}
<br/>
<br/>
{this.notAttendingFormSubmitButton()}
</Form>
</Card>
</React.Fragment>
);
}
}
176 changes: 87 additions & 89 deletions components/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/

const { SubMenu } = Menu;
const { Header, Content, Sider } = Layout;
import {
AppstoreOutlined,
MenuUnfoldOutlined,
MenuFoldOutlined,
PieChartOutlined,
DesktopOutlined,
ContainerOutlined,
MailOutlined,
} from '@ant-design/icons';
import stylesheet from 'antd/dist/antd.min.css';
import AttendanceComponent from '../components/attendanceComponent';


// const Nav = () => (
Expand Down Expand Up @@ -125,6 +135,21 @@ export default class Nav extends React.Component {
}
}

renderContent = () => {
if(this.props.attendanceOptionClicked){
return <AttendanceComponent
studentAttendanceSubmitClicked={this.props.studentAttendanceSubmitClicked}
studentAttendanceClicked={this.props.studentAttendanceClicked}
studentAttendanceSickClicked={this.props.studentAttendanceSickClicked}
studentAttendanceOtherReasonClicked={this.props.studentAttendanceOtherReasonClicked}
handleStudentAttendanceOtherReasonInput={this.props.handleStudentAttendanceOtherReasonInput}
markAllStudentAtendanceTheSame={this.props.markAllStudentAtendanceTheSame}
handleStudentAttendanceDateRange={this.props.handleStudentAttendanceDateRange}
attendanceComponent={this.props.attendanceComponent}
/>
}
}

render() {
return (
<React.Fragment>
Expand All @@ -139,96 +164,69 @@ export default class Nav extends React.Component {
</Menu>
</Header>
<Layout>
<Sider width={200} className="site-layout-background">
<Menu
mode="inline"
defaultSelectedKeys={['1']}
defaultOpenKeys={['sub1']}
style={{ height: '100%', borderRight: 0 }}
onClick={(e) => this.props.handleMenuClick(e.key)}
>
<SubMenu
key="sub1"
title={
<span>
<UserOutlined />
{this.props.currentUserClicked.displayName ?
this.props.currentUserClicked.displayName
:
this.props.currentUserClicked.email
}
</span>
}
>
{
this.props.currentUserDoc.teacherStudents ?
this.props.currentUserDoc.teacherStudents.map(function(d, idx){
return (
<Menu.Item key={idx}>
{
d.fullName ?
d.fullName :
d.email
<Sider width={200} className="site-layout-background">
<Menu
mode="inline"
defaultSelectedKeys={['1']}
defaultOpenKeys={['sub1']}
style={{ height: '100%', borderRight: 0 }}
onClick={(e) => this.props.handleMenuClick(e.key)}
>
<SubMenu
key="sub1"
title={
<span>
<UserOutlined />
{this.props.currentUserClicked.displayName ?
this.props.currentUserClicked.displayName
:
this.props.currentUserClicked.email
}
</Menu.Item>
)
})
:
null
}
{
this.props.currentUserClicked.email !== this.props.currentUserDoc.email ?
this.showTeacherInOptions() :
null
}
</SubMenu>
<SubMenu
key="sub2"
title={
<span>
<LaptopOutlined />
subnav 2
</span>
}
>
<Menu.Item key="5">option5</Menu.Item>
<Menu.Item key="6">option6</Menu.Item>
<Menu.Item key="7">option7</Menu.Item>
<Menu.Item key="8">option8</Menu.Item>
</SubMenu>
<SubMenu
key="sub3"
title={
<span>
<NotificationOutlined />
subnav 3
</span>
}
>
<Menu.Item key="9">option9</Menu.Item>
<Menu.Item key="10">option10</Menu.Item>
<Menu.Item key="11">option11</Menu.Item>
<Menu.Item key="12">option12</Menu.Item>
</SubMenu>
</Menu>
</Sider>
<Layout style={{ padding: '0 24px 24px' }}>
<Breadcrumb style={{ margin: '16px 0' }}>
<Breadcrumb.Item>Home</Breadcrumb.Item>
<Breadcrumb.Item>List</Breadcrumb.Item>
<Breadcrumb.Item>App</Breadcrumb.Item>
</Breadcrumb>
<Content
className="site-layout-background"
style={{
padding: 24,
margin: 0,
minHeight: 280,
}}
>
Content
</Content>
</Layout>
</span>
}
>
{
this.props.currentUserDoc.teacherStudents ?
this.props.currentUserDoc.teacherStudents.map(function(d, idx){
return (
<Menu.Item key={idx}>
{
d.fullName ?
d.fullName :
d.email
}
</Menu.Item>
)
})
:
null
}
{
this.props.currentUserClicked.email !== this.props.currentUserDoc.email ?
this.showTeacherInOptions() :
null
}
</SubMenu>
<Menu.Item key="-2">
<PieChartOutlined />
<span>Student Attendance</span>
</Menu.Item>
</Menu>
</Sider>
<Layout style={{ padding: '0 24px 24px' }}>
<Content
className="site-layout-background"
style={{
padding: 24,
margin: 0,
minHeight: 280,
}}
>
{
this.renderContent()
}
</Content>
</Layout>
</Layout>
</Layout>
</React.Fragment>
Expand Down
Loading

0 comments on commit 6b0a03f

Please sign in to comment.