colouring-montreal/app/src/frontend/building/multi-edit.tsx

64 lines
2.4 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { Link } from 'react-router-dom';
2019-05-09 04:16:36 -04:00
import { useMultiEditData } from '../hooks/use-multi-edit-data';
2019-11-26 07:09:27 -05:00
import ErrorBox from '../components/error-box';
import InfoBox from '../components/info-box';
import { dataFields } from '../config/data-fields-config';
2019-05-09 04:16:36 -04:00
2019-11-07 02:39:26 -05:00
import DataEntry from './data-components/data-entry';
import { Category } from '../config/categories-config';
2019-11-07 02:39:26 -05:00
2019-11-26 07:09:27 -05:00
interface MultiEditProps {
category: string;
}
const MultiEdit: React.FC<MultiEditProps> = (props) => {
const [data, error] = useMultiEditData();
const isLike = props.category === Category.Community;
2019-05-09 04:16:36 -04:00
return (
<section className='data-section'>
<header className={`section-header view ${props.category} background-${props.category}`}>
<h2 className="h2">{
isLike ?
<>Like Me!</> :
<>Copy {props.category} data</>
}</h2>
</header>
<div className="section-body">
<form>
2019-11-26 07:09:27 -05:00
{
error ?
<ErrorBox msg={error} /> :
<InfoBox msg={
isLike ?
'Click all the buildings that you like and think contribute to the city!' :
'Click buildings one at a time to colour using the data below'
} />
2019-11-26 07:09:27 -05:00
}
2020-02-03 17:35:32 -05:00
{
!isLike && data &&
Object.keys(data).map((key => (
2020-02-03 17:35:32 -05:00
<DataEntry
key={key}
title={dataFields[key]?.title ?? `Unknown field (${key})`}
2020-02-03 17:35:32 -05:00
slug={key}
disabled={true}
value={data[key]}
/>
)))
2020-02-03 17:35:32 -05:00
}
</form>
<form className='buttons-container'>
<Link to={`/view/${props.category}`} className='btn btn-secondary'>Back to view</Link>
<Link to={`/edit/${props.category}`} className='btn btn-secondary'>Back to edit</Link>
</form>
</div>
</section>
2019-05-09 04:16:36 -04:00
);
2019-11-07 03:13:30 -05:00
};
2019-05-09 04:16:36 -04:00
export default MultiEdit;