diff --git a/app/routes/circulars._archive._index/route.tsx b/app/routes/circulars._archive._index/route.tsx index 7255fd2831..d6d5a75649 100644 --- a/app/routes/circulars._archive._index/route.tsx +++ b/app/routes/circulars._archive._index/route.tsx @@ -102,9 +102,16 @@ export async function action({ request }: ActionFunctionArgs) { if (circularId === undefined) throw new Response('circularId is required', { status: 400 }) if (!user?.name || !user.email) throw new Response(null, { status: 403 }) - + const submitter = getFormDataString(data, 'submitter') + const createdOn = getFormDataString(data, 'createdOn') + if (!submitter || !createdOn) throw new Response(null, { status: 400 }) await createChangeRequest( - { circularId: parseFloat(circularId), ...props }, + { + circularId: parseFloat(circularId), + ...props, + submitter, + createdOn: parseFloat(createdOn), + }, user ) await postZendeskRequest({ diff --git a/app/routes/circulars.correction.$circularId.tsx b/app/routes/circulars.correction.$circularId.tsx index 243ab77a57..4e94e220c7 100644 --- a/app/routes/circulars.correction.$circularId.tsx +++ b/app/routes/circulars.correction.$circularId.tsx @@ -36,6 +36,7 @@ export async function loader({ defaultFormat: circular.format, circularId: circular.circularId, submitter: circular.submitter, + createdOn: circular.createdOn, searchString: '', } } diff --git a/app/routes/circulars.edit.$circularId/CircularEditForm.tsx b/app/routes/circulars.edit.$circularId/CircularEditForm.tsx index e01b6aa798..1ad7dfcee5 100644 --- a/app/routes/circulars.edit.$circularId/CircularEditForm.tsx +++ b/app/routes/circulars.edit.$circularId/CircularEditForm.tsx @@ -29,7 +29,10 @@ import { import { type CircularFormat, bodyIsValid, + dateIsValid, + formatDateISO, subjectIsValid, + submitterIsValid, } from '../circulars/circulars.lib' import { RichEditor } from './RichEditor' import { @@ -39,6 +42,7 @@ import { import { CircularsKeywords } from '~/components/CircularsKeywords' import CollapsableInfo from '~/components/CollapsableInfo' import Spinner from '~/components/Spinner' +import TimeAgo from '~/components/TimeAgo' import { useFeature } from '~/root' function SyntaxExample({ @@ -118,6 +122,7 @@ export function CircularEditForm({ defaultBody, defaultSubject, searchString, + createdOn, intent, }: { formattedContributor: string @@ -127,6 +132,7 @@ export function CircularEditForm({ defaultBody: string defaultSubject: string searchString: string + createdOn?: number intent: 'correction' | 'edit' | 'new' }) { let formSearchString = '?index' @@ -140,10 +146,14 @@ export function CircularEditForm({ const [body, setBody] = useState(defaultBody) const [subject, setSubject] = useState(defaultSubject) const [format, setFormat] = useState(defaultFormat) + const [date, setDate] = useState(createdOn) + const [updatedSubmitter, setUpdatedSubmitter] = useState(submitter) const bodyValid = bodyIsValid(body) + const dateValid = dateIsValid(date) + const submitterValid = submitterIsValid(updatedSubmitter) const [showPreview, setShowPreview] = useState(false) const sending = Boolean(useNavigation().formData) - const valid = subjectValid && bodyValid + const valid = subjectValid && bodyValid && dateValid && submitterValid let headerText, saveButtonText switch (intent) { @@ -165,7 +175,10 @@ export function CircularEditForm({ const changesHaveBeenMade = body.trim() !== defaultBody.trim() || subject.trim() !== defaultSubject.trim() || - format !== defaultFormat + format !== defaultFormat || + submitter !== updatedSubmitter?.trim() || + createdOn !== date + return (

{headerText} GCN Circular

@@ -183,21 +196,12 @@ export function CircularEditForm({ id="submitter" type="text" defaultValue={submitter} + onChange={(event) => setUpdatedSubmitter(event.target.value)} required - onChange={({ target: { value } }) => { - // setSubject(value) - // setSubjectValid(subjectIsValid(value)) - }} /> )} - - - Submission Date - - - {circularId === undefined ? 'From' : 'Editor'} @@ -212,6 +216,25 @@ export function CircularEditForm({ + + + Date + {createdOn ? ( +
+ {formatDateISO(createdOn)} + +
+ ) : ( + + setDate(value ? Date.parse(value) : undefined) + } + name="datePicker" + id="datePicker" + /> + )} +
() + dayjs.locale(locale) + dayjs.extend(RelativeTime) + const dateTimeFormat = new Intl.DateTimeFormat(locale.name, { + dateStyle: 'full', + timeStyle: 'long', + timeZone: 'utc', + }) + return ( <>

Circular {circular.circularId}

Original Author

- {circular.submitter} +

Requestor

{correction.requestor} +

Created On

+

Subject

diff --git a/app/routes/circulars/circulars.lib.ts b/app/routes/circulars/circulars.lib.ts index 060b2ddf09..ed03ba5f6d 100644 --- a/app/routes/circulars/circulars.lib.ts +++ b/app/routes/circulars/circulars.lib.ts @@ -37,6 +37,8 @@ export interface CircularChangeRequest extends CircularMetadata { requestorSub: string requestorEmail: string format: CircularFormat + submitter: string + createdOn: number } export interface CircularChangeRequestKeys { @@ -130,6 +132,15 @@ export function formatIsValid(format: string): format is CircularFormat { return (circularFormats as any as string[]).includes(format) } +/** For updated dates, check that the date is valid */ +export function dateIsValid(date?: number) { + return date !== undefined +} + +export function submitterIsValid(submitter?: string) { + return submitter !== undefined +} + export function emailIsAutoReply(subject: string) { const lowercaseSubject = subject.toLowerCase() return emailAutoReplyChecklist.some((x) => lowercaseSubject.includes(x)) diff --git a/app/routes/circulars/circulars.server.ts b/app/routes/circulars/circulars.server.ts index 08864b594c..295857697b 100644 --- a/app/routes/circulars/circulars.server.ts +++ b/app/routes/circulars/circulars.server.ts @@ -368,14 +368,7 @@ export async function getVersions(circularId: number): Promise { export async function createChangeRequest( item: Omit< Circular, - | 'sub' - | 'createdOn' - | 'submitter' - | 'submittedHow' - | 'bibcode' - | 'editedBy' - | 'version' - | 'editedOn' + 'sub' | 'submittedHow' | 'bibcode' | 'editedBy' | 'version' | 'editedOn' >, user?: User ) { @@ -391,6 +384,8 @@ export async function createChangeRequest( requestorSub: user.sub, requestorEmail: user.email, requestor, + createdOn: item.createdOn, + submitter: item.submitter, }) await sendEmail({ @@ -518,6 +513,8 @@ export async function approveChangeRequest( editedBy: `${formatAuthor(user)} on behalf of ${changeRequest.requestor}`, editedOn: Date.now(), format: changeRequest.format, + submitter: changeRequest.submitter, + createdOn: changeRequest.createdOn, }) await deleteChangeRequestRaw(circularId, requestorSub)