import React, { Fragment } from 'react';
import { Link, Redirect } from 'react-router-dom';
import { parse } from 'query-string';
import PropTypes from 'prop-types';
import Sidebar from './sidebar';
import InfoBox from '../components/info-box';
import { sanitiseURL } from '../helpers';
const CONFIG = [];
const MultiEdit = (props) => {
if (!props.user){
return
}
const cat = props.match.params.cat;
if (cat === 'like') {
// special case for likes
return (
);
}
const q = parse(props.location.search);
let data: object;
if (cat === 'like'){
data = { like: true }
} else {
try {
// TODO: verify what happens if data is string[]
data = JSON.parse(q.data as string);
} catch (error) {
console.error(error, q)
data = {}
}
}
const title = sectionTitleFromCat(cat);
return (
{
Object.keys(data).map((key => {
const label = fieldTitleFromSlug(key);
return
}))
}
);
}
MultiEdit.propTypes = {
user: PropTypes.object,
match: PropTypes.object,
location: PropTypes.object
}
const DataEntry = (props) => {
let content;
if (props.value != null && props.value !== '') {
if (typeof(props.value) === 'boolean') {
content = (props.value)? 'Yes' : 'No'
} else if (Array.isArray(props.value)) {
if (props.value.length) {
content =
{
props.value.map((item, index) => {
return - {item}
})
}
} else {
content = '\u00A0'
}
} else {
content = props.value
}
} else {
content = '\u00A0'
}
return (
{props.label}
{content}
)
}
function sectionTitleFromCat(cat) {
for (let index = 0; index < CONFIG.length; index++) {
const section = CONFIG[index];
if (section.slug === cat) {
return section.title
}
}
return undefined
}
function fieldTitleFromSlug(slug) {
const fields = CONFIG.reduce(
(prev, section) => {
const el = prev.concat(
section.fields.filter(
(field: any) => field.slug === slug // TODO: remove any
)
)
return el
}, []
)
if (fields.length === 1 && fields[0].title) {
return fields[0].title
} else {
console.error('Expected single match, got', fields)
}
}
export default MultiEdit;