Skip to content

Commit

Permalink
Merge branch 'main' into 318-rating-lookup-cypress-test
Browse files Browse the repository at this point in the history
  • Loading branch information
m-triassi authored Jan 31, 2022
2 parents 214cd0b + a99f69d commit ab94ac4
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/BulkEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function store(BulkEntryStoreRequest $request)
$entriesCount = round($difference * $data['frequency']);

$character = Character::findOrFail($data['character_id']);
$character->stubEntries(0, $entriesCount, $data['adventure_id']);
$character->stubEntries(0, $entriesCount, $data['adventure']['id']);
$entries = $character->entries()->where('created_at', ">=", now())->get();

foreach ($entries as $index => $entry) {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/BulkEntryStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function rules()
{
return [
'character_id' => "required|exists:characters,id",
'adventure_id' => "nullable|exists:adventures,id",
'adventure.id' => "required|exists:adventures,id",
'start_date' => "required|date",
'end_date' => "nullable|date|after:start_date",
// How often a session was ran, measured in times/week
Expand Down
160 changes: 79 additions & 81 deletions resources/js/Components/Form/BulkEntryCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AdapterDateFns from '@mui/lab/AdapterDateFns'
import DateTimePicker from '@mui/lab/DateTimePicker'
import LocalizationProvider from '@mui/lab/LocalizationProvider'
import {Button, Grid, TextField, Typography} from '@mui/material'
import {ErrorText, Link, Select, StepperForm} from 'Components'
import {Autocomplete, ErrorText, Link, Select, StepperForm} from 'Components'
import React, {useState} from 'react'
import styled from 'styled-components'
import {adventureType} from 'Types/adventure-data'
Expand All @@ -23,8 +23,9 @@ type BulkEntryFormDataType = {
start_date: Date | null
end_date: Date | null
frequency: number
adventure_id: number
adventure: any | undefined
character_id: number
[key: string]: any
}

const StyledGrid = styled(Grid)`
Expand Down Expand Up @@ -56,7 +57,7 @@ const BulkEntryCreateForm = ({character, adventures}: BulkEntryCreateFormPropTyp
start_date: new Date(),
end_date: new Date(),
frequency: 1,
adventure_id: 0,
adventure: undefined,
character_id: character.id,
}

Expand All @@ -68,86 +69,83 @@ const BulkEntryCreateForm = ({character, adventures}: BulkEntryCreateFormPropTyp
const stepTitles = [{label: 'Details'}]

const stepOneContent = (
<>
<Grid container>
<Grid item xs={12}>
<Typography>
Fill out the following fields about your future sessions.
</Typography>
</Grid>
<StyledGrid item xs={12} md={5}>
<Select
id='adventure_id'
required
label='Adventure'
name='Adventure Title'
value={data.adventure_id}
onChange={(e) =>
setData('adventure_id', parseInt(e.target.value))
}
options={adventures}
/>
{errors?.adventure_id && <ErrorText message={errors?.adventure_id} />}
</StyledGrid>
<StyledGrid item xs={12} md={2} />
<StyledGrid item xs={12} md={2}>
<Select
id='frequency'
required
label='Frequency'
name='Frequency'
value={data.frequency}
onChange={(e) => setData('frequency', parseFloat(e.target.value))}
options={frequencies}
<Grid container>
<Grid item xs={12}>
<Typography>
Fill out the following fields about your future sessions.
</Typography>
</Grid>
<StyledGrid item xs={12} md={5}>
<Autocomplete
id='adventures'
fieldKey='adventures'
onChange={(_, value) => setData('adventure', value)}
defaultValue={data.adventure}
getOptionLabel={(option) => `${option.code} - ${option.title}`}
options={adventures}
resetUrl={route('entry-bulk.create').concat(
`?character_id=${character.id}`,
)}
/>
{errors['adventure.id'] && <ErrorText message={errors['adventure.id']} />}
</StyledGrid>
<StyledGrid item xs={12} md={2} />
<StyledGrid item xs={12} md={2}>
<Select
id='frequency'
required
label='Frequency'
name='Frequency'
value={data.frequency}
onChange={(e) => setData('frequency', parseFloat(e.target.value))}
options={frequencies}
/>
{errors?.frequency && <ErrorText message={errors?.frequency} />}
</StyledGrid>
<StyledGrid item xs={12} md={3}>
<StyledTextField
disabled
fullWidth
variant='filled'
id='id'
label='Assigned Character'
defaultValue={character.name}
/>
</StyledGrid>
<StyledGrid item xs={12} md={5}>
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DateTimePicker
label='Start Date and Time'
value={data.start_date}
inputFormat='yyyy-MM-dd HH:mm'
onChange={(e) => {
setData('start_date', e)
}}
renderInput={(params) => (
<TextField {...params} fullWidth id='start_date' />
)}
/>
{errors?.frequency && <ErrorText message={errors?.frequency} />}
</StyledGrid>
<StyledGrid item xs={12} md={1} />
<StyledGrid item xs={12} md={2}>
<StyledTextField
disabled
fullWidth
variant='filled'
id='id'
label='Assigned Character'
defaultValue={character.name}
</LocalizationProvider>
{errors?.start_date && <ErrorText message={errors?.start_date} />}
</StyledGrid>
<StyledGrid item xs={12} md={2} />
<StyledGrid item xs={12} md={5}>
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DateTimePicker
label='End Date and Time'
value={data.end_date}
inputFormat='yyyy-MM-dd HH:mm'
onChange={(e) => {
setData('end_date', e)
}}
renderInput={(params) => (
<TextField {...params} fullWidth id='end_date' />
)}
/>
</StyledGrid>
<StyledGrid item xs={12} md={5}>
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DateTimePicker
label='Start Date and Time'
value={data.start_date}
inputFormat='yyyy-MM-dd HH:mm'
onChange={(e) => {
setData('start_date', e)
}}
renderInput={(params) => (
<TextField {...params} fullWidth id='start_date' />
)}
/>
</LocalizationProvider>
{errors?.start_date && <ErrorText message={errors?.start_date} />}
</StyledGrid>
<StyledGrid item xs={12} md={2} />
<StyledGrid item xs={12} md={5}>
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DateTimePicker
label='End Date and Time'
value={data.end_date}
inputFormat='yyyy-MM-dd HH:mm'
onChange={(e) => {
setData('end_date', e)
}}
renderInput={(params) => (
<TextField {...params} fullWidth id='end_date' />
)}
/>
</LocalizationProvider>
{errors?.end_date && <ErrorText message={errors?.end_date} />}
</StyledGrid>
</Grid>
</>
</LocalizationProvider>
{errors?.end_date && <ErrorText message={errors?.end_date} />}
</StyledGrid>
</Grid>
)

const stepContent = [stepOneContent]
Expand Down
3 changes: 2 additions & 1 deletion resources/js/Components/Form/DmEntryCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type DmEntryFormDataType = {
type: string
user_id: number | null | undefined
adventure: any
[key: string]: any
}

type ItemDataType = {
Expand Down Expand Up @@ -132,7 +133,7 @@ const DmEntryCreateForm = ({
: route('dm-entry.index')
}
/>
{errors?.adventure_id && <ErrorText message={errors?.adventure_id} />}
{errors['adventure.id'] && <ErrorText message={errors['adventure.id']} />}
</StyledGrid>
{type === 'Create' && <StyledGrid item md={2} />}
<StyledGrid item xs={12} md={type === 'Edit' ? 12 : 5}>
Expand Down
3 changes: 2 additions & 1 deletion resources/js/Components/Form/EntryCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type EntryFormDataType = {
character_id: number
user_id: number | null | undefined
adventure: any
[key: string]: any
}

const StyledGrid = styled(Grid)`
Expand Down Expand Up @@ -137,7 +138,7 @@ const EntryCreateForm = ({
: route('character.show', [character.id])
}
/>
{errors?.adventure_id && <ErrorText message={errors?.adventure_id} />}
{errors['adventure.id'] && <ErrorText message={errors['adventure.id']} />}
</StyledGrid>
{type === 'Create' && <StyledGrid item md={2} />}
<StyledGrid item xs={12} md={type === 'Edit' ? 12 : 5}>
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Http/Controllers/BulkEntryControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function entries_can_be_created_in_bulk()
$responseWeekly = $this->actingAs($characters[0]->user)
->post(route('entry-bulk.store'), [
'character_id' => $characters[0]->id,
'adventure_id' => $adventure->id,
'adventure' => ['id' => $adventure->id],
'start_date' => $startDate,
'end_date' => $endDate,
'frequency' => $freqWeekly,
Expand All @@ -55,7 +55,7 @@ public function entries_can_be_created_in_bulk()
$responseBiweekly = $this->actingAs($characters[1]->user)
->post(route('entry-bulk.store'), [
'character_id' => $characters[1]->id,
'adventure_id' => $adventure->id,
'adventure' => ['id' => $adventure->id],
'start_date' => $startDate,
'end_date' => $endDate,
'frequency' => $freqBiweekly,
Expand All @@ -64,7 +64,7 @@ public function entries_can_be_created_in_bulk()
$responseTwiceWeekly = $this->actingAs($characters[2]->user)
->post(route('entry-bulk.store'), [
'character_id' => $characters[2]->id,
'adventure_id' => $adventure->id,
'adventure' => ['id' => $adventure->id],
'start_date' => $startDate,
'end_date' => $endDate,
'frequency' => $freqTwiceWeekly,
Expand Down

0 comments on commit ab94ac4

Please sign in to comment.