feat: add graphql support (#349)

* fix: eslint warnings

* refactor: use ramda + sanctuary instead of lodash

* refactor: use prettier-standard for formatting

* feat: enable security

* feat: add graphql

* chore: remove trailing commas from linter

* docs: new scripts on react and new-admin-server

* feat: handle authentication on graphql

* fix: perf improvement to date picker

* chore: add insecure-dev script to run servers
This commit is contained in:
Rafael Taranto 2019-12-24 14:36:41 +00:00 committed by Josh Harvey
parent 49f434f1d1
commit b8e0c2175b
182 changed files with 8827 additions and 4623 deletions

View file

@ -1,11 +1,11 @@
import React, { useState } from 'react'
import moment from 'moment'
import { toInteger, range, map, concat } from 'lodash/fp'
import { makeStyles } from '@material-ui/core/styles'
import moment from 'moment'
import * as R from 'ramda'
import React, { useState } from 'react'
import { ReactComponent as Arrow } from '../../styling/icons/arrow/month_change.svg'
import { primaryColor, zircon } from '../../styling/variables'
import typographyStyles from '../typography/styles'
import { ReactComponent as Arrow } from 'src/styling/icons/arrow/month_change.svg'
import { primaryColor, zircon } from 'src/styling/variables'
import typographyStyles from 'src/components/typography/styles'
import Tile from './Tile'
@ -73,33 +73,72 @@ const Calendar = ({ minDate, maxDate, handleSelect, ...props }) => {
const classes = useStyles()
const weekdays = moment.weekdaysMin().map(day => day.slice(0, 1))
const firstDayOfMonth = (month) => toInteger(moment(month).startOf('month').format('d'))
const monthLength = (month) => toInteger(moment(month).endOf('month').format('D'))
const firstDayOfMonth = month =>
Number.parseInt(
moment(month)
.startOf('month')
.format('d')
)
const monthLength = month =>
Number.parseInt(
moment(month)
.endOf('month')
.format('D')
)
const monthdays = (month) => {
const monthdays = month => {
const lastMonth = moment(month).subtract(1, 'month')
const lastMonthRange = range(firstDayOfMonth(month) - 1, -1)
const lastMonthDays = map(i => moment(lastMonth).endOf('month').subtract(i, 'days'))(lastMonthRange)
const thisMonthRange = range(0, monthLength(month))
const thisMonthDays = map(i => moment(month).startOf('month').add(i, 'days'))(thisMonthRange)
const nextMonth = moment(month).add(1, 'month')
const nextMonthRange = range(0, 42 - lastMonthDays.length - thisMonthDays.length)
const nextMonthDays = map(i => moment(nextMonth).startOf('month').add(i, 'days'))(nextMonthRange)
const lastMonthRange = R.range(firstDayOfMonth(month) - 1, -1)
const lastMonthDays = R.map(i =>
moment(lastMonth)
.endOf('month')
.subtract(i, 'days')
)(lastMonthRange)
return concat(concat(lastMonthDays, thisMonthDays), nextMonthDays)
const thisMonthRange = R.range(0, monthLength(month))
const thisMonthDays = R.map(i =>
moment(month)
.startOf('month')
.add(i, 'days')
)(thisMonthRange)
const nextMonth = moment(month).add(1, 'month')
const nextMonthRange = R.range(
0,
42 - lastMonthDays.length - thisMonthDays.length
)
const nextMonthDays = R.map(i =>
moment(nextMonth)
.startOf('month')
.add(i, 'days')
)(nextMonthRange)
return R.concat(R.concat(lastMonthDays, thisMonthDays), nextMonthDays)
}
const getRow = (month, row) => monthdays(month).slice(row * 7 - 7, row * 7)
const handleNavPrev = (currentMonth) => {
const handleNavPrev = currentMonth => {
const prevMonth = moment(currentMonth).subtract(1, 'month')
if (!minDate) setCurrentDisplayedMonth(prevMonth)
else setCurrentDisplayedMonth(prevMonth.isSameOrAfter(minDate, 'month') ? prevMonth : currentDisplayedMonth)
else {
setCurrentDisplayedMonth(
prevMonth.isSameOrAfter(minDate, 'month')
? prevMonth
: currentDisplayedMonth
)
}
}
const handleNavNext = (currentMonth) => {
const handleNavNext = currentMonth => {
const nextMonth = moment(currentMonth).add(1, 'month')
if (!maxDate) setCurrentDisplayedMonth(nextMonth)
else setCurrentDisplayedMonth(nextMonth.isSameOrBefore(maxDate, 'month') ? nextMonth : currentDisplayedMonth)
else {
setCurrentDisplayedMonth(
nextMonth.isSameOrBefore(maxDate, 'month')
? nextMonth
: currentDisplayedMonth
)
}
}
return (
@ -108,9 +147,13 @@ const Calendar = ({ minDate, maxDate, handleSelect, ...props }) => {
<button onClick={() => handleNavPrev(currentDisplayedMonth)}>
<Arrow />
</button>
<span>{`${currentDisplayedMonth.format('MMMM')} ${currentDisplayedMonth.format('YYYY')}`}</span>
<span>
{`${currentDisplayedMonth.format(
'MMMM'
)} ${currentDisplayedMonth.format('YYYY')}`}
</span>
<button onClick={() => handleNavNext(currentDisplayedMonth)}>
<Arrow transform='rotate(180)' />
<Arrow transform="rotate(180)" />
</button>
</div>
<table className={classes.table}>
@ -122,16 +165,20 @@ const Calendar = ({ minDate, maxDate, handleSelect, ...props }) => {
</tr>
</thead>
<tbody>
{range(1, 8).map((row, key) => (
{R.range(1, 8).map((row, key) => (
<tr key={key}>
{getRow(currentDisplayedMonth, row).map((day, key) => (
<td key={key} onClick={() => handleSelect(day, minDate, maxDate)}>
<td
key={key}
onClick={() => handleSelect(day, minDate, maxDate)}>
<Tile
isDisabled={(maxDate && day.isAfter(maxDate, 'day')) || (minDate && day.isBefore(minDate, 'day'))}
isDisabled={
(maxDate && day.isAfter(maxDate, 'day')) ||
(minDate && day.isBefore(minDate, 'day'))
}
isLowerBound={day.isSame(props.from, 'day')}
isUpperBound={day.isSame(props.to, 'day')}
isBetween={day.isBetween(props.from, props.to, 'day', [])}
>
isBetween={day.isBetween(props.from, props.to, 'day', [])}>
{day.format('D')}
</Tile>
</td>