Skip to content

Commit

Permalink
Merge pull request #2434 from target/ts-conversion-RotationCreateDialog
Browse files Browse the repository at this point in the history
ui/rotations: convert RotationCreateDialog to ts
  • Loading branch information
tony-tvu authored Jun 17, 2022
2 parents 1dea0b0 + 548c5ed commit a2c2cbd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import React, { useState } from 'react'
import { gql, useMutation } from '@apollo/client'
import p from 'prop-types'
import { nonFieldErrors, fieldErrors } from '../util/errutil'
import FormDialog from '../dialogs/FormDialog'
import RotationForm from './RotationForm'
import { DateTime } from 'luxon'
import { Redirect } from 'wouter'

interface Value {
name: string
description: string
timeZone: string
type: string
start: string
shiftLength: number
favorite: boolean
}

const mutation = gql`
mutation ($input: CreateRotationInput!) {
createRotation(input: $input) {
Expand All @@ -20,18 +29,17 @@ const mutation = gql`
}
}
`
const initialValue = {
name: '',
description: '',
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
type: 'daily',
start: DateTime.local().plus({ hours: 1 }).startOf('hour').toISO(),
shiftLength: 1,
favorite: true,
}

const RotationCreateDialog = (props) => {
const [value, setValue] = useState(initialValue)
const RotationCreateDialog = (props: { onClose?: () => void }): JSX.Element => {
const [value, setValue] = useState<Value>({
name: '',
description: '',
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
type: 'daily',
start: DateTime.local().plus({ hours: 1 }).startOf('hour').toISO(),
shiftLength: 1,
favorite: true,
})
const [createRotationMutation, { loading, data, error }] = useMutation(
mutation,
{
Expand Down Expand Up @@ -66,8 +74,4 @@ const RotationCreateDialog = (props) => {
)
}

RotationCreateDialog.propTypes = {
onClose: p.func,
}

export default RotationCreateDialog
1 change: 1 addition & 0 deletions web/src/app/rotations/RotationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,5 @@ RotationForm.propTypes = {
),

onChange: p.func.isRequired,
disabled: p.bool,
}

0 comments on commit a2c2cbd

Please sign in to comment.