2019-11-05 15:13:10 -05:00
|
|
|
import React from 'react';
|
2021-02-08 11:03:30 -05:00
|
|
|
import { Link } from 'react-router-dom';
|
2019-05-09 04:16:36 -04:00
|
|
|
|
2021-02-22 01:59:24 -05:00
|
|
|
import { useMultiEditData } from '../hooks/use-multi-edit-data';
|
2019-11-26 07:09:27 -05:00
|
|
|
import ErrorBox from '../components/error-box';
|
2019-08-14 04:21:42 -04:00
|
|
|
import InfoBox from '../components/info-box';
|
2021-08-22 21:26:58 -04:00
|
|
|
import { allFieldsConfig } 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';
|
|
|
|
|
2019-11-26 07:09:27 -05:00
|
|
|
interface MultiEditProps {
|
|
|
|
category: string;
|
2019-11-05 15:13:10 -05:00
|
|
|
}
|
2019-08-23 09:18:08 -04:00
|
|
|
|
2019-11-05 15:13:10 -05:00
|
|
|
const MultiEdit: React.FC<MultiEditProps> = (props) => {
|
2021-02-22 01:59:24 -05:00
|
|
|
const [data, error] = useMultiEditData();
|
2019-05-10 11:10:16 -04:00
|
|
|
|
2019-05-09 04:16:36 -04:00
|
|
|
return (
|
2021-02-22 01:59:24 -05:00
|
|
|
<section className='data-section'>
|
|
|
|
<header className={`section-header view ${props.category} background-${props.category}`}>
|
2021-08-22 21:26:58 -04:00
|
|
|
<h2 className="h2">Paste {props.category} data</h2>
|
2021-02-22 01:59:24 -05:00
|
|
|
</header>
|
|
|
|
<div className="section-body">
|
|
|
|
<form>
|
2019-11-26 07:09:27 -05:00
|
|
|
{
|
|
|
|
error ?
|
|
|
|
<ErrorBox msg={error} /> :
|
2021-08-22 21:26:58 -04:00
|
|
|
<InfoBox msg='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
|
|
|
{
|
2021-08-22 21:26:58 -04:00
|
|
|
data &&
|
2021-02-22 01:59:24 -05:00
|
|
|
Object.keys(data).map((key => (
|
2020-02-03 17:35:32 -05:00
|
|
|
<DataEntry
|
2021-02-22 01:59:24 -05:00
|
|
|
key={key}
|
2021-08-22 21:26:58 -04:00
|
|
|
title={allFieldsConfig[key]?.title ?? `Unknown field (${key})`}
|
2020-02-03 17:35:32 -05:00
|
|
|
slug={key}
|
|
|
|
disabled={true}
|
|
|
|
value={data[key]}
|
2021-02-22 01:59:24 -05:00
|
|
|
/>
|
|
|
|
)))
|
2020-02-03 17:35:32 -05:00
|
|
|
}
|
2021-02-22 01:59:24 -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;
|