2020-03-19 16:13:51 +01:00
|
|
|
import Link from 'next/link';
|
2020-03-21 20:48:46 +01:00
|
|
|
import { useState, forwardRef } from 'react';
|
2020-04-11 21:07:13 +02:00
|
|
|
import date from 'date-and-time';
|
2020-03-21 23:03:30 +01:00
|
|
|
import Loader from '../Loader';
|
2020-05-01 02:27:30 +02:00
|
|
|
import { API_URL } from '../../utils/config/config';
|
2020-05-01 21:01:03 +02:00
|
|
|
import './FunctionCard.css';
|
2020-03-19 16:13:51 +01:00
|
|
|
|
2020-03-21 18:24:10 +01:00
|
|
|
const FunctionCard = forwardRef((props, ref) => {
|
2020-03-21 16:43:37 +01:00
|
|
|
|
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
|
|
|
|
const handleLoad = () => {
|
|
|
|
setIsLoading(false);
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:27:30 +02:00
|
|
|
const handleError = (event) => {
|
|
|
|
event.target.src = API_URL + "/images/functions/default.png";
|
|
|
|
}
|
|
|
|
|
2020-03-23 14:42:26 +01:00
|
|
|
const isFormOrArticle = (props.type === 'form' || props.type === 'article');
|
|
|
|
|
2020-03-21 16:43:37 +01:00
|
|
|
return (
|
2020-03-21 23:54:08 +01:00
|
|
|
<Link
|
2020-04-11 21:07:13 +02:00
|
|
|
{
|
|
|
|
...(props.isAdmin) ?
|
|
|
|
{
|
|
|
|
href: "/admin/[slug]",
|
|
|
|
as: `/admin/${props.slug}`
|
|
|
|
}
|
|
|
|
:
|
|
|
|
{
|
|
|
|
href: (isFormOrArticle) ? "/functions/[slug]" : `/functions/${props.slug}`,
|
|
|
|
as: `/functions/${props.slug}`
|
|
|
|
}
|
|
|
|
}
|
2020-03-21 23:54:08 +01:00
|
|
|
>
|
|
|
|
{/* FunctionCard a une hauteur pendant chargement */}
|
2020-03-21 20:48:46 +01:00
|
|
|
<div ref={ref} style={isLoading ? { height: "360px", justifyContent: "center" } : null} className={"FunctionCard col-sm-24 col-md-10 col-xl-7"}>
|
2020-03-21 23:54:08 +01:00
|
|
|
|
2020-03-21 20:48:46 +01:00
|
|
|
{isLoading && <Loader width="125px" height="125px" />}
|
2020-03-21 23:54:08 +01:00
|
|
|
|
2020-03-21 20:48:46 +01:00
|
|
|
<div className={`FunctionCard__container ${isLoading ? "d-none" : ""}`}>
|
|
|
|
<div className="FunctionCard__top">
|
2020-05-01 02:27:30 +02:00
|
|
|
<img onLoad={handleLoad} onError={handleError} className="FunctionCard__image" alt={props.title} src={API_URL + props.image} />
|
2020-03-21 20:48:46 +01:00
|
|
|
<h2 className="FunctionCard__title">{props.title}</h2>
|
2020-04-22 22:01:18 +02:00
|
|
|
<p className="FunctionCard__description text-center">{props.description}</p>
|
2020-03-21 20:48:46 +01:00
|
|
|
</div>
|
|
|
|
<div className="FunctionCard__info">
|
2020-04-11 21:07:13 +02:00
|
|
|
<p className="FunctionCard__category" style={{ backgroundColor: props.categorie.color }}>{props.categorie.name}</p>
|
|
|
|
<p className="FunctionCard__publication-date">{date.format(new Date(props.createdAt), 'DD/MM/YYYY', true)}</p>
|
2020-03-21 16:43:37 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-03-21 20:48:46 +01:00
|
|
|
</div>
|
2020-03-21 16:43:37 +01:00
|
|
|
</Link>
|
|
|
|
);
|
2020-04-10 20:20:07 +02:00
|
|
|
});
|
2020-03-19 16:13:51 +01:00
|
|
|
|
|
|
|
export default FunctionCard;
|