2019-08-14 16:54:00 -04:00
|
|
|
import React from 'react';
|
2021-02-22 01:59:24 -05:00
|
|
|
import { useAuth } from '../auth-context';
|
2018-09-11 15:59:59 -04:00
|
|
|
|
2021-02-22 01:59:24 -05:00
|
|
|
import { categoriesConfig, Category } from '../config/categories-config';
|
|
|
|
import { categoryUiConfig } from '../config/category-ui-config';
|
|
|
|
import { Building, UserVerified } from '../models/building';
|
2019-08-14 06:36:38 -04:00
|
|
|
|
2019-11-07 02:39:26 -05:00
|
|
|
import BuildingNotFound from './building-not-found';
|
2019-10-15 09:37:23 -04:00
|
|
|
|
|
|
|
interface BuildingViewProps {
|
2021-02-22 01:59:24 -05:00
|
|
|
cat: Category;
|
2019-10-30 08:28:10 -04:00
|
|
|
mode: 'view' | 'edit';
|
2019-11-05 15:13:10 -05:00
|
|
|
building?: Building;
|
|
|
|
building_like?: boolean;
|
2020-08-04 10:54:49 -04:00
|
|
|
user_verified?: any;
|
2021-02-22 01:59:24 -05:00
|
|
|
onBuildingUpdate: (buildingId: number, updatedData: Building) => void;
|
|
|
|
onBuildingLikeUpdate: (buildingId: number, updatedData: boolean) => void;
|
|
|
|
onUserVerifiedUpdate: (buildingId: number, updatedData: UserVerified) => void;
|
2019-10-15 09:37:23 -04:00
|
|
|
}
|
2019-08-14 06:36:38 -04:00
|
|
|
|
2019-08-14 14:33:26 -04:00
|
|
|
/**
|
|
|
|
* Top-level container for building view/edit form
|
|
|
|
*
|
|
|
|
* @param props
|
|
|
|
*/
|
2019-10-15 09:37:23 -04:00
|
|
|
const BuildingView: React.FunctionComponent<BuildingViewProps> = (props) => {
|
2021-02-22 01:59:24 -05:00
|
|
|
const { user } = useAuth();
|
|
|
|
const DataContainer = categoryUiConfig[props.cat];
|
|
|
|
|
|
|
|
const categoryConfig = categoriesConfig[props.cat];
|
|
|
|
|
|
|
|
if(categoryConfig == undefined) {
|
|
|
|
return <BuildingNotFound mode="view" />;
|
2019-08-14 14:33:26 -04:00
|
|
|
}
|
2021-02-22 01:59:24 -05:00
|
|
|
|
|
|
|
const {
|
|
|
|
name,
|
|
|
|
aboutUrl,
|
|
|
|
intro,
|
|
|
|
inactive = false
|
|
|
|
} = categoryConfig;
|
|
|
|
|
|
|
|
return <DataContainer
|
|
|
|
{...props}
|
|
|
|
title={name}
|
|
|
|
help={aboutUrl}
|
|
|
|
intro={intro}
|
|
|
|
inactive={inactive}
|
|
|
|
user={user}
|
|
|
|
/>;
|
2019-11-07 03:13:30 -05:00
|
|
|
};
|
2018-10-03 16:47:49 -04:00
|
|
|
|
2018-09-09 17:22:44 -04:00
|
|
|
export default BuildingView;
|