Client - localize Calendar w/ date-fns - fix #40
This commit is contained in:
parent
ed0e467404
commit
caa866c816
@ -95,7 +95,7 @@ test('should throw an error if the username is too short', async t => {
|
|||||||
await t
|
await t
|
||||||
.expect(Selector('H1').withText('Register').exists).ok()
|
.expect(Selector('H1').withText('Register').exists).ok()
|
||||||
.expect(Selector('code').withText(
|
.expect(Selector('code').withText(
|
||||||
'Username: 3 to 12 characters required.').exists).ok()
|
'3 to 12 characters required for username.').exists).ok()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should throw an error if the user is too long', async t => {
|
test('should throw an error if the user is too long', async t => {
|
||||||
@ -115,7 +115,7 @@ test('should throw an error if the user is too long', async t => {
|
|||||||
await t
|
await t
|
||||||
.expect(Selector('H1').withText('Register').exists).ok()
|
.expect(Selector('H1').withText('Register').exists).ok()
|
||||||
.expect(Selector('code').withText(
|
.expect(Selector('code').withText(
|
||||||
'Username: 3 to 12 characters required.').exists).ok()
|
'3 to 12 characters required for username.').exists).ok()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should throw an error if the email is invalid', async t => {
|
test('should throw an error if the email is invalid', async t => {
|
||||||
@ -173,5 +173,5 @@ test('should throw an error if the password is too short', async t => {
|
|||||||
await t
|
await t
|
||||||
.expect(Selector('H1').withText('Register').exists).ok()
|
.expect(Selector('H1').withText('Register').exists).ok()
|
||||||
.expect(Selector('code').withText(
|
.expect(Selector('code').withText(
|
||||||
'Password: 8 characters required.').exists).ok()
|
'8 characters required for password.').exists).ok()
|
||||||
})
|
})
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
startOfWeek,
|
startOfWeek,
|
||||||
subMonths,
|
subMonths,
|
||||||
} from 'date-fns'
|
} from 'date-fns'
|
||||||
|
import { enGB, fr } from 'date-fns/locale'
|
||||||
import React, { Fragment } from 'react'
|
import React, { Fragment } from 'react'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
@ -46,7 +47,7 @@ class Calendar extends React.Component {
|
|||||||
this.props.loadMonthActivities(this.state.startDate, this.state.endDate)
|
this.props.loadMonthActivities(this.state.startDate, this.state.endDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
renderHeader() {
|
renderHeader(localeOptions) {
|
||||||
const dateFormat = 'MMM yyyy'
|
const dateFormat = 'MMM yyyy'
|
||||||
return (
|
return (
|
||||||
<div className="header row flex-middle">
|
<div className="header row flex-middle">
|
||||||
@ -54,7 +55,9 @@ class Calendar extends React.Component {
|
|||||||
<i className="fa fa-chevron-left" aria-hidden="true" />
|
<i className="fa fa-chevron-left" aria-hidden="true" />
|
||||||
</div>
|
</div>
|
||||||
<div className="col col-center">
|
<div className="col col-center">
|
||||||
<span>{format(this.state.currentMonth, dateFormat)}</span>
|
<span>
|
||||||
|
{format(this.state.currentMonth, dateFormat, localeOptions)}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="col col-end" onClick={() => this.handleNextMonth()}>
|
<div className="col col-end" onClick={() => this.handleNextMonth()}>
|
||||||
<i className="fa fa-chevron-right" aria-hidden="true" />
|
<i className="fa fa-chevron-right" aria-hidden="true" />
|
||||||
@ -63,7 +66,7 @@ class Calendar extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
renderDays() {
|
renderDays(localeOptions) {
|
||||||
const dateFormat = 'EEE'
|
const dateFormat = 'EEE'
|
||||||
const days = []
|
const days = []
|
||||||
const { startDate } = this.state
|
const { startDate } = this.state
|
||||||
@ -71,7 +74,7 @@ class Calendar extends React.Component {
|
|||||||
for (let i = 0; i < 7; i++) {
|
for (let i = 0; i < 7; i++) {
|
||||||
days.push(
|
days.push(
|
||||||
<div className="col col-center" key={i}>
|
<div className="col col-center" key={i}>
|
||||||
{format(addDays(startDate, i), dateFormat)}
|
{format(addDays(startDate, i), dateFormat, localeOptions)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -175,11 +178,14 @@ class Calendar extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const localeOptions = {
|
||||||
|
locale: this.props.language === 'fr' ? fr : enGB,
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="card activity-card">
|
<div className="card activity-card">
|
||||||
<div className="calendar">
|
<div className="calendar">
|
||||||
{this.renderHeader()}
|
{this.renderHeader(localeOptions)}
|
||||||
{this.renderDays()}
|
{this.renderDays(localeOptions)}
|
||||||
{this.renderCells()}
|
{this.renderCells()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -190,6 +196,7 @@ class Calendar extends React.Component {
|
|||||||
export default connect(
|
export default connect(
|
||||||
state => ({
|
state => ({
|
||||||
activities: state.calendarActivities.data,
|
activities: state.calendarActivities.data,
|
||||||
|
language: state.language,
|
||||||
sports: state.sports.data,
|
sports: state.sports.data,
|
||||||
user: state.user,
|
user: state.user,
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user