import _ from "lodash" import React from "react" import ResponseAnswersComponent from "./ResponseAnswersComponent" import moment from "moment" import { FormDesign } from "./formDesign" import { Schema } from "@mwater/expressions" import { LocalizeString } from "ez-localize" import { InnerFormContext } from "./formContext" import { Response } from "./response" export interface ResponseArchivesComponentProps { formDesign: FormDesign response: Response /** Schema of the */ schema: Schema /** Defaults to english */ locale?: string /** Localizer to use */ T: LocalizeString /** Form context to use */ formCtx: InnerFormContext /** The archives */ history: Response[] /** Events usernames indexed by _id */ eventsUsernames: { [key: string]: { username: string } } } /** Show complete change history of response */ export default class ResponseArchivesComponent extends React.Component { renderRecord = (record: Response, previousRecord: Response) => { return (
{this.props.T("Changes made by")}{" "} {record.modified!.by ? this.props.eventsUsernames[record.modified!.by]?.username : this.props.T("Anonymous")} {" "} {this.props.T("on")}{" "} {moment(record.modified!.on).format("lll")}
) } render() { if (this.props.history.length === 0) { return (
{this.props.T("No changes made since submission")}
) } return (
{_.map(this.props.history, (record, index) => { if (index === 0) { return this.renderRecord(this.props.response, record) } else { return this.renderRecord(this.props.history[index - 1], record) } })}
) } }