Skip to content

Commit

Permalink
rename fields for consistency, add hidden field to fix time not getti…
Browse files Browse the repository at this point in the history
…ng set correctly
  • Loading branch information
dakota002 committed May 21, 2024
1 parent 56e8790 commit 85ee49c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
2 changes: 2 additions & 0 deletions app/routes/circulars._archive._index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export async function action({ request }: ActionFunctionArgs) {
if (user.groups.includes(moderatorGroup)) {
submitter = getFormDataString(data, 'submitter')
createdOnDate = getFormDataString(data, 'createdOnDate')
console.log(createdOnDate)
createdOnTime = getFormDataString(data, 'createdOnTime')
console.log(createdOnTime)
createdOn = Date.parse(`${createdOnDate} ${createdOnTime} UTC`)
}
await createChangeRequest(
Expand Down
6 changes: 3 additions & 3 deletions app/routes/circulars.correction.$circularId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export async function loader({
defaultSubject: circular.subject,
defaultFormat: circular.format,
circularId: circular.circularId,
submitter: circular.submitter,
createdOnDate: defaultDateTime[0],
createdOnTime: defaultDateTime[1].substring(0, 5),
defaultSubmitter: circular.submitter,
defaultCreatedOnDate: defaultDateTime[0],
defaultCreatedOnTime: defaultDateTime[1].substring(0, 5),
searchString: '',
}
}
Expand Down
42 changes: 24 additions & 18 deletions app/routes/circulars.edit.$circularId/CircularEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,24 @@ export function SyntaxReference() {
export function CircularEditForm({
formattedContributor,
circularId,
submitter,
defaultSubmitter,
defaultFormat,
defaultBody,
defaultSubject,
searchString,
createdOnDate,
createdOnTime,
defaultCreatedOnDate,
defaultCreatedOnTime,
intent,
}: {
formattedContributor: string
circularId?: number
submitter?: string
defaultSubmitter?: string
defaultFormat?: CircularFormat
defaultBody: string
defaultSubject: string
searchString: string
createdOnDate?: string
createdOnTime?: string
defaultCreatedOnDate?: string
defaultCreatedOnTime?: string
intent: 'correction' | 'edit' | 'new'
}) {
let formSearchString = '?index'
Expand All @@ -142,12 +142,12 @@ export function CircularEditForm({
const [body, setBody] = useState(defaultBody)
const [subject, setSubject] = useState(defaultSubject)
const [format, setFormat] = useState(defaultFormat)
const [date, setDate] = useState(createdOnDate)
const [time, setTime] = useState(createdOnTime ?? '12:00')
const [date, setDate] = useState(defaultCreatedOnDate)
const [time, setTime] = useState(defaultCreatedOnTime ?? '12:00')
const dateValid = circularId ? dateIsValid(date, time) : true

const [updatedSubmitter, setUpdatedSubmitter] = useState(submitter)
const submitterValid = circularId ? submitterIsValid(updatedSubmitter) : true
const [submitter, setUpdatedSubmitter] = useState(defaultSubmitter)
const submitterValid = circularId ? submitterIsValid(submitter) : true
const bodyValid = bodyIsValid(body)
const sending = Boolean(useNavigation().formData)
const valid = subjectValid && bodyValid && dateValid && submitterValid
Expand Down Expand Up @@ -176,10 +176,10 @@ export function CircularEditForm({
body.trim() !== defaultBody.trim() ||
subject.trim() !== defaultSubject.trim() ||
format !== defaultFormat ||
submitter !== updatedSubmitter?.trim() ||
defaultSubmitter !== submitter?.trim() ||
(date && date.replace(/(\d{2})\/(\d{2})\/(\d{4})/, '$3-$1-$2')) !==
createdOnDate ||
time !== createdOnTime
defaultCreatedOnDate ||
time !== defaultCreatedOnTime

const userIsModerator = useModStatus()

Expand All @@ -201,7 +201,7 @@ export function CircularEditForm({
name="submitter"
id="submitter"
type="text"
defaultValue={submitter}
defaultValue={defaultSubmitter}
onChange={(event) =>
setUpdatedSubmitter(event.target.value)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ export function CircularEditForm({
<InputGroup className="border-0">
<InputPrefix className="wide-input-prefix">Date</InputPrefix>
<DatePicker
defaultValue={createdOnDate}
defaultValue={defaultCreatedOnDate}
className={classnames(styles.DatePicker, 'border-1px ')}
onChange={(value) => {
setDate(value ?? '')
Expand All @@ -243,11 +243,17 @@ export function CircularEditForm({
/>
</InputGroup>
<InputGroup className="tablet:grid-col-auto">
<InputPrefix className="wide-input-prefix">Time</InputPrefix>
<TimePicker
<input
type="hidden"
id="createdOnTime"
name="createdOnTime"
defaultValue={time}
value={time}
/>
<InputPrefix className="wide-input-prefix">Time</InputPrefix>
<TimePicker
id="createdOnTimeSetter"
name="createdOnTimeSetter"
defaultValue={defaultCreatedOnTime}
className="margin-top-neg-3"
onChange={(value) => {
setTime(value ?? '')
Expand Down
2 changes: 1 addition & 1 deletion app/routes/circulars.edit.$circularId/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function loader({
defaultSubject: circular.subject,
defaultFormat: circular.format,
circularId: circular.circularId,
submitter: circular.submitter,
defaultSubmitter: circular.submitter,
searchString: '',
}
}
Expand Down

0 comments on commit 85ee49c

Please sign in to comment.