🎨 Configure standardJS

This commit is contained in:
divlo
2020-08-03 12:04:07 +02:00
parent e22e62a749
commit 58f47c7480
120 changed files with 12271 additions and 10025 deletions

View File

@ -1,108 +1,109 @@
import Link from 'next/link';
import { useEffect, useState, forwardRef, useContext, Fragment } from 'react';
import date from 'date-and-time';
import htmlParser from 'html-react-parser';
import { UserContext } from '../../../contexts/UserContext';
import { API_URL } from '../../../utils/config/config';
import ReactMarkdown from 'react-markdown';
import CodeBlock from "../../CodeBlock";
import api from '../../../utils/api';
import './CommentCard.css';
import Link from 'next/link'
import { useEffect, useState, forwardRef, useContext } from 'react'
import date from 'date-and-time'
import htmlParser from 'html-react-parser'
import { UserContext } from '../../../contexts/UserContext'
import { API_URL } from '../../../utils/config/config'
import ReactMarkdown from 'react-markdown'
import CodeBlock from '../../CodeBlock'
import api from '../../../utils/api'
import './CommentCard.css'
const CommentCard = forwardRef((props, ref) => {
const { isAuth, user } = useContext(UserContext)
const [isEditing, setEditing] = useState(false)
const [editInput, setEditInput] = useState('')
const [message, setMessage] = useState('')
const { isAuth, user } = useContext(UserContext);
const [isEditing, setEditing] = useState(false);
const [editInput, setEditInput] = useState("");
const [message, setMessage] = useState("");
useEffect(() => {
setEditInput(props.message)
}, [])
useEffect(() => {
setEditInput(props.message);
}, []);
const deleteCommentById = async () => {
props.manageComment.setLoadingComments(true);
if (isAuth && user.token != undefined) {
try {
await api.delete(`/comments/${props.id}`, { headers: { 'Authorization': user.token } });
const newCommentsData = { ...props.manageComment.commentsData };
const commentIndex = newCommentsData.rows.findIndex((value) => value.id === props.id);
newCommentsData.rows.splice(commentIndex, 1);
props.manageComment.setCommentsData({ hasMore: props.manageComment.commentsData.hasMore, rows: newCommentsData.rows });
} catch {}
}
props.manageComment.setLoadingComments(false);
const deleteCommentById = async () => {
props.manageComment.setLoadingComments(true)
if (isAuth && user.token != null) {
try {
await api.delete(`/comments/${props.id}`, { headers: { Authorization: user.token } })
const newCommentsData = { ...props.manageComment.commentsData }
const commentIndex = newCommentsData.rows.findIndex((value) => value.id === props.id)
newCommentsData.rows.splice(commentIndex, 1)
props.manageComment.setCommentsData({ hasMore: props.manageComment.commentsData.hasMore, rows: newCommentsData.rows })
} catch {}
}
props.manageComment.setLoadingComments(false)
}
const handleChange = (event) => {
setEditInput(event.target.value);
}
const handleChange = (event) => {
setEditInput(event.target.value)
}
const handleSubmit = (event) => {
event.preventDefault();
api.put(`/comments/${props.id}`, { message: editInput }, { headers: { 'Authorization': user.token } })
.then((_response) => {
setEditing(false);
})
.catch((error) => {
setMessage(`<p class="form-error"><b>Erreur:</b> ${error.response.data.message}</p>`);
});
}
const handleSubmit = (event) => {
event.preventDefault()
api.put(`/comments/${props.id}`, { message: editInput }, { headers: { Authorization: user.token } })
.then((_response) => {
setEditing(false)
})
.catch((error) => {
setMessage(`<p class="form-error"><b>Erreur:</b> ${error.response.data.message}</p>`)
})
}
const editComment = () => {
setEditing(true);
setMessage("");
}
const editComment = () => {
setEditing(true)
setMessage('')
}
return (
<div ref={ref} className="CommentCard col-24">
<div className="CommentCard__container">
<div className="row">
<Link href={"/users/[name]"} as={`/users/${props.user.name}`}>
<img className="CommentCard__user-logo" src={API_URL + props.user.logo} alt={props.user.name} />
</Link>
<span className="CommentCard__message-info">
<Link href={"/users/[name]"} as={`/users/${props.user.name}`}>
<a>{props.user.name}</a>
</Link>
&nbsp;- {date.format(new Date(props.createdAt), 'DD/MM/YYYY à HH:mm', true)}
</span>
</div>
<div className="row">
<div className="col-24">
{
(!isEditing) ?
<Fragment>
<div className="CommentCard__message">
<ReactMarkdown source={editInput} renderers={{ code: CodeBlock }} />
</div>
{(isAuth && user.name === props.user.name) &&
<p style={{ fontSize: '15px', margin: '15px 0 0 0', fontStyle: 'italic' }}>
<a onClick={deleteCommentById} href="#">supprimer</a>
&nbsp;-&nbsp;
<a style={{ cursor: 'pointer' }} onClick={editComment}>modifier</a>
</p>
}
</Fragment>
:
<form onSubmit={handleSubmit}>
<div className="form-group FunctionComments__post-group">
<label className="form-label" htmlFor="commentEdit">Modifier le commentaire :</label>
<textarea style={{ height: 'auto' }} value={editInput} onChange={handleChange} name="commentEdit" id="commentEdit" className="form-control" rows="5" placeholder="Idée d'amélioration, avis, remarque, partage d'expérience personnel, ... (Markdown autorisé)"></textarea>
</div>
<div className="form-group" style={{ marginTop: '0.7em' }}>
<button type="submit" className="btn btn-dark">Envoyer</button>
</div>
<div className="text-center">
{htmlParser(message)}
</div>
</form>
}
</div>
</div>
</div>
return (
<div ref={ref} className='CommentCard col-24'>
<div className='CommentCard__container'>
<div className='row'>
<Link href='/users/[name]' as={`/users/${props.user.name}`}>
<img className='CommentCard__user-logo' src={API_URL + props.user.logo} alt={props.user.name} />
</Link>
<span className='CommentCard__message-info'>
<Link href='/users/[name]' as={`/users/${props.user.name}`}>
<a>{props.user.name}</a>
</Link>
&nbsp;- {date.format(new Date(props.createdAt), 'DD/MM/YYYY à HH:mm', true)}
</span>
</div>
);
});
<div className='row'>
<div className='col-24'>
{
(!isEditing)
? (
<>
<div className='CommentCard__message'>
<ReactMarkdown source={editInput} renderers={{ code: CodeBlock }} />
</div>
{(isAuth && user.name === props.user.name) &&
<p style={{ fontSize: '15px', margin: '15px 0 0 0', fontStyle: 'italic' }}>
<a onClick={deleteCommentById} href='#'>supprimer</a>
&nbsp;-&nbsp;
<a style={{ cursor: 'pointer' }} onClick={editComment}>modifier</a>
</p>}
</>
)
: (
<form onSubmit={handleSubmit}>
<div className='form-group FunctionComments__post-group'>
<label className='form-label' htmlFor='commentEdit'>Modifier le commentaire :</label>
<textarea style={{ height: 'auto' }} value={editInput} onChange={handleChange} name='commentEdit' id='commentEdit' className='form-control' rows='5' placeholder="Idée d'amélioration, avis, remarque, partage d'expérience personnel, ... (Markdown autorisé)" />
</div>
<div className='form-group' style={{ marginTop: '0.7em' }}>
<button type='submit' className='btn btn-dark'>Envoyer</button>
</div>
<div className='text-center'>
{htmlParser(message)}
</div>
</form>
)
}
</div>
</div>
</div>
</div>
)
})
export default CommentCard;
export default CommentCard

View File

@ -1,11 +1,11 @@
import htmlParser from 'html-react-parser';
import htmlParser from 'html-react-parser'
const FunctionArticle = ({ article }) => {
return (
<div style={{ marginBottom: '50px' }} className="container-fluid">
{(article != undefined) ? htmlParser(article) : <p className="text-center">L'article n'est pas encore disponible.</p>}
</div>
);
return (
<div style={{ marginBottom: '50px' }} className='container-fluid'>
{(article != null) ? htmlParser(article) : <p className='text-center'>L'article n'est pas encore disponible.</p>}
</div>
)
}
export default FunctionArticle;
export default FunctionArticle

View File

@ -1,115 +1,114 @@
import { Fragment, useState, useEffect, useContext, useRef, useCallback } from 'react';
import Link from 'next/link';
import { UserContext } from '../../../contexts/UserContext';
import CommentCard from '../CommentCard/CommentCard';
import Loader from '../../Loader';
import api from '../../../utils/api';
import './FunctionComments.css';
import { useState, useEffect, useContext, useRef, useCallback } from 'react'
import Link from 'next/link'
import { UserContext } from '../../../contexts/UserContext'
import CommentCard from '../CommentCard/CommentCard'
import Loader from '../../Loader'
import api from '../../../utils/api'
import './FunctionComments.css'
const FunctionComments = ({ functionId }) => {
// State pour poster un commentaire
const { isAuth, user } = useContext(UserContext)
const [inputState, setInputState] = useState({})
// State pour poster un commentaire
const { isAuth, user } = useContext(UserContext);
const [inputState, setInputState] = useState({});
// State pour afficher les commentaires
const [commentsData, setCommentsData] = useState({ hasMore: true, rows: [] })
const [isLoadingComments, setLoadingComments] = useState(true)
const [pageComments, setPageComments] = useState(1)
// State pour afficher les commentaires
const [commentsData, setCommentsData] = useState({ hasMore: true, rows: [] });
const [isLoadingComments, setLoadingComments] = useState(true);
const [pageComments, setPageComments] = useState(1);
// Récupère les commentaires si la page change
useEffect(() => {
getCommentsData().then((data) => setCommentsData({
hasMore: data.hasMore,
rows: [...commentsData.rows, ...data.rows]
}))
}, [pageComments])
// Récupère les commentaires si la page change
useEffect(() => {
getCommentsData().then((data) => setCommentsData({
hasMore: data.hasMore,
rows: [...commentsData.rows, ...data.rows]
}));
}, [pageComments]);
// Permet la pagination au scroll
const observer = useRef()
const lastCommentCardRef = useCallback((node) => {
if (isLoadingComments) return
if (observer.current) observer.current.disconnect()
observer.current = new window.IntersectionObserver((entries) => {
if (entries[0].isIntersecting && commentsData.hasMore) {
setPageComments(pageComments + 1)
}
}, { threshold: 1 })
if (node) observer.current.observe(node)
}, [isLoadingComments, commentsData.hasMore])
// Permet la pagination au scroll
const observer = useRef();
const lastCommentCardRef = useCallback((node) => {
if (isLoadingComments) return;
if (observer.current) observer.current.disconnect();
observer.current = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting && commentsData.hasMore) {
setPageComments(pageComments + 1);
const getCommentsData = async () => {
setLoadingComments(true)
const { data } = await api.get(`/comments/${functionId}/?page=${pageComments}&limit=10`)
setLoadingComments(false)
return data
}
const handleChange = (event) => {
const inputStateNew = { ...inputState }
inputStateNew[event.target.name] = event.target.value
setInputState(inputStateNew)
}
const handleSubmit = async (event) => {
setLoadingComments(true)
event.preventDefault()
const token = user.token
if (isAuth && token != null && inputState.commentPost != null) {
try {
const response = await api.post(`/comments/${functionId}`, { message: inputState.commentPost }, { headers: { Authorization: token } })
const comment = { ...response.data, user: { name: user.name, logo: user.logo } }
setCommentsData({ hasMore: commentsData.hasMore, rows: [comment, ...commentsData.rows] })
setInputState({ commentPost: '' })
} catch { }
}
setLoadingComments(false)
}
return (
<>
<div className='FunctionComments__post container-fluid'>
<div className='row FunctionComments__row'>
<div className='col-24'>
{
(isAuth)
? (
<form onSubmit={handleSubmit}>
<div className='form-group FunctionComments__post-group'>
<label className='form-label' htmlFor='commentPost'>Ajouter un commentaire :</label>
<textarea className='FunctionComments__textarea form-control' value={inputState.commentPost} onChange={handleChange} name='commentPost' id='commentPost' placeholder="Idée d'amélioration, avis, remarque, partage d'expérience personnel, ... (Markdown autorisé)" />
</div>
<div className='form-group' style={{ marginTop: '0.7em' }}>
<button type='submit' className='btn btn-dark'>Envoyer</button>
</div>
</form>
)
: (
<p className='text-center'>
Vous devez être <Link href='/users/login'><a>connecté</a></Link> pour poster un commentaire.
</p>
)
}
}, { threshold: 1 });
if (node) observer.current.observe(node);
}, [isLoadingComments, commentsData.hasMore]);
const getCommentsData = () => {
setLoadingComments(true);
return new Promise(async (next) => {
const result = await api.get(`/comments/${functionId}/?page=${pageComments}&limit=10`);
setLoadingComments(false);
next(result.data);
});
}
const handleChange = (event) => {
const inputStateNew = { ...inputState };
inputStateNew[event.target.name] = event.target.value;
setInputState(inputStateNew);
}
const handleSubmit = async (event) => {
setLoadingComments(true);
event.preventDefault();
const token = user.token;
if (isAuth && token != undefined && inputState.commentPost != undefined) {
try {
const response = await api.post(`/comments/${functionId}`, { message: inputState.commentPost }, { headers: { 'Authorization': token } });
const comment = { ...response.data, user: { name: user.name, logo: user.logo } };
setCommentsData({ hasMore: commentsData.hasMore, rows: [comment, ...commentsData.rows] });
setInputState({ commentPost: "" });
} catch { }
}
setLoadingComments(false);
}
return (
<Fragment>
<div className="FunctionComments__post container-fluid">
<div className="row FunctionComments__row">
<div className="col-24">
{
(isAuth) ?
<form onSubmit={handleSubmit}>
<div className="form-group FunctionComments__post-group">
<label className="form-label" htmlFor="commentPost">Ajouter un commentaire :</label>
<textarea className="FunctionComments__textarea form-control" value={inputState.commentPost} onChange={handleChange} name="commentPost" id="commentPost" placeholder="Idée d'amélioration, avis, remarque, partage d'expérience personnel, ... (Markdown autorisé)"></textarea>
</div>
<div className="form-group" style={{ marginTop: '0.7em' }}>
<button type="submit" className="btn btn-dark">Envoyer</button>
</div>
</form>
:
<p className="text-center">
Vous devez être <Link href={'/users/login'}><a>connecté</a></Link> pour poster un commentaire.
</p>
}
</div>
</div>
</div>
<div className="container-fluid">
{isLoadingComments &&
<div className="row justify-content-center">
<Loader />
</div>
}
<div className="row justify-content-center">
{commentsData.rows.map((comment, index) => {
// Si c'est le dernier élément
if (commentsData.rows.length === index + 1) {
return <CommentCard key={comment.id} ref={lastCommentCardRef} { ...comment } manageComment={{ setCommentsData, commentsData, setLoadingComments }} />;
}
return <CommentCard key={comment.id} { ...comment } manageComment={{ setCommentsData, commentsData, setLoadingComments }} />;
})}
</div>
</div>
</Fragment>
);
</div>
</div>
</div>
<div className='container-fluid'>
{isLoadingComments &&
<div className='row justify-content-center'>
<Loader />
</div>}
<div className='row justify-content-center'>
{commentsData.rows.map((comment, index) => {
// Si c'est le dernier élément
if (commentsData.rows.length === index + 1) {
return <CommentCard key={comment.id} ref={lastCommentCardRef} {...comment} manageComment={{ setCommentsData, commentsData, setLoadingComments }} />
}
return <CommentCard key={comment.id} {...comment} manageComment={{ setCommentsData, commentsData, setLoadingComments }} />
})}
</div>
</div>
</>
)
}
export default FunctionComments;
export default FunctionComments

View File

@ -1,71 +1,69 @@
import { useState, useEffect, useContext } from 'react';
import Link from 'next/link';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faStar } from '@fortawesome/free-solid-svg-icons';
import { faStar as farStar } from '@fortawesome/free-regular-svg-icons';
import date from 'date-and-time';
import { UserContext } from '../../contexts/UserContext';
import api from '../../utils/api';
import { API_URL } from '../../utils/config/config';
import '../FunctionCard/FunctionCard.css';
import { useState, useEffect, useContext } from 'react'
import Link from 'next/link'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faStar } from '@fortawesome/free-solid-svg-icons'
import { faStar as farStar } from '@fortawesome/free-regular-svg-icons'
import date from 'date-and-time'
import { UserContext } from '../../contexts/UserContext'
import api from '../../utils/api'
import { API_URL } from '../../utils/config/config'
import '../FunctionCard/FunctionCard.css'
const FunctionComponentTop = (props) => {
const { isAuth, user } = useContext(UserContext)
const [isFavorite, setIsFavorite] = useState(false)
const { isAuth, user } = useContext(UserContext);
const [isFavorite, setIsFavorite] = useState(false);
useEffect(() => {
if (isAuth && user.token != null) {
fetchFavorite()
}
}, [isAuth])
useEffect(() => {
if (isAuth && user.token != undefined) {
fetchFavorite();
const fetchFavorite = async () => {
try {
const favoriteResponse = await api.get(`/favorites/${props.id}`, { headers: { Authorization: user.token } })
setIsFavorite(favoriteResponse.data.isFavorite)
} catch {}
}
const toggleFavorite = async () => {
if (isAuth && user.token != null) {
try {
if (isFavorite) {
const response = await api.delete(`/favorites/${props.id}`, { headers: { Authorization: user.token } })
if (response.status === 200) return setIsFavorite(false)
}
}, [isAuth]);
const fetchFavorite = async () => {
try {
const favoriteResponse = await api.get(`/favorites/${props.id}`, { headers: { 'Authorization': user.token } });
setIsFavorite(favoriteResponse.data.isFavorite);
} catch {}
const response = await api.post(`/favorites/${props.id}`, {}, { headers: { Authorization: user.token } })
if (response.status === 201) return setIsFavorite(true)
} catch {}
}
}
const toggleFavorite = async () => {
if (isAuth && user.token != undefined) {
try {
if (isFavorite) {
const response = await api.delete(`/favorites/${props.id}`, { headers: { 'Authorization': user.token } });
if (response.status === 200) return setIsFavorite(false);
}
const response = await api.post(`/favorites/${props.id}`, {}, { headers: { 'Authorization': user.token } });
if (response.status === 201) return setIsFavorite(true);
} catch {}
}
}
const handleError = (event) => {
event.target.src = API_URL + '/images/functions/default.png'
}
const handleError = (event) => {
event.target.src = API_URL + "/images/functions/default.png";
}
return (
<div className='container-fluid'>
<div className='row justify-content-center text-center'>
<div className='FunctionComponent__top col-24'>
return (
<div className="container-fluid">
<div className="row justify-content-center text-center">
<div className="FunctionComponent__top col-24">
{(isAuth) &&
<FontAwesomeIcon onClick={toggleFavorite} {...(isFavorite) ? { icon: faStar } : { icon: farStar }} title={(isFavorite) ? 'Retirer la fonction des favoris' : 'Ajouter la fonction aux favoris'} className='FunctionComponent__star-favorite' />}
{(isAuth) &&
<FontAwesomeIcon onClick={toggleFavorite} { ...(isFavorite) ? { icon: faStar } : { icon: farStar } } title={(isFavorite) ? "Retirer la fonction des favoris" : "Ajouter la fonction aux favoris"} className="FunctionComponent__star-favorite" />
}
<img onError={handleError} className="FunctionComponent__image" src={API_URL + props.image} alt={props.title} />
<h1 className="FunctionComponent__title title-important">{props.title}</h1>
<p className="FunctionComponent__description">{props.description}</p>
<div className="FunctionCard__info">
<Link href={`/functions?categoryId=${props.categorieId}`}>
<a className="FunctionCard__category" style={{ backgroundColor: props.categorie.color, color: 'inherit' }}>{props.categorie.name}</a>
</Link>
<p className="FunctionCard__publication-date">{date.format(new Date(props.createdAt), 'DD/MM/YYYY', true)}</p>
</div>
</div>
</div>
<img onError={handleError} className='FunctionComponent__image' src={API_URL + props.image} alt={props.title} />
<h1 className='FunctionComponent__title title-important'>{props.title}</h1>
<p className='FunctionComponent__description'>{props.description}</p>
<div className='FunctionCard__info'>
<Link href={`/functions?categoryId=${props.categorieId}`}>
<a className='FunctionCard__category' style={{ backgroundColor: props.categorie.color, color: 'inherit' }}>{props.categorie.name}</a>
</Link>
<p className='FunctionCard__publication-date'>{date.format(new Date(props.createdAt), 'DD/MM/YYYY', true)}</p>
</div>
</div>
);
</div>
</div>
)
}
export default FunctionComponentTop;
export default FunctionComponentTop

View File

@ -1,161 +1,160 @@
import { Fragment, useState, useEffect } from 'react';
import Loader from '../Loader';
import htmlParser from 'html-react-parser';
import dynamic from 'next/dynamic';
import api from '../../utils/api';
import fr from 'date-fns/locale/fr';
import { registerLocale } from "react-datepicker";
import date from 'date-and-time';
import "react-datepicker/dist/react-datepicker.css";
import { useState, useEffect } from 'react'
import Loader from '../Loader'
import htmlParser from 'html-react-parser'
import dynamic from 'next/dynamic'
import api from '../../utils/api'
import fr from 'date-fns/locale/fr'
import { registerLocale } from 'react-datepicker'
import date from 'date-and-time'
import 'react-datepicker/dist/react-datepicker.css'
registerLocale('fr', fr);
registerLocale('fr', fr)
const FunctionForm = (props) => {
const [inputState, setInputState] = useState({})
const [message, setMessage] = useState('')
const [isLoading, setIsLoading] = useState(false)
const [inputState, setInputState] = useState({});
const [message, setMessage] = useState("");
const [isLoading, setIsLoading] = useState(false);
// inputState par défaut
useEffect(() => {
const inputStateNew = { ...inputState }
props.inputsArray.forEach((input) => {
if (input.type === 'select' && input.options.length > 0) {
inputStateNew[input.name] = input.options[0].value
}
})
setInputState(inputStateNew)
}, [])
// inputState par défaut
useEffect(() => {
const inputStateNew = { ...inputState };
props.inputsArray.forEach((input) => {
if (input.type === "select" && input.options.length > 0) {
inputStateNew[input.name] = input.options[0].value;
}
});
setInputState(inputStateNew);
}, []);
const handleSubmit = (event) => {
setIsLoading(true)
event.preventDefault()
api.post(`/functions/${props.slug}`, inputState)
.then((response) => {
setMessage(response.data.resultHTML)
setIsLoading(false)
})
.catch((error) => {
setMessage(error.response.data.message)
setIsLoading(false)
})
}
const handleSubmit = (event) => {
setIsLoading(true);
event.preventDefault();
api.post(`/functions/${props.slug}`, inputState)
.then((response) => {
setMessage(response.data.resultHTML);
setIsLoading(false);
})
.catch((error) => {
setMessage(error.response.data.message);
setIsLoading(false);
});
}
const handleChange = (event) => {
const inputStateNew = { ...inputState }
inputStateNew[event.target.name] = event.target.value
setInputState(inputStateNew)
}
const handleChange = (event) => {
const inputStateNew = { ...inputState };
inputStateNew[event.target.name] = event.target.value;
setInputState(inputStateNew);
}
if (props.inputsArray.length <= 0) {
return (
<div className="FunctionComponent__slide text-center">
<p>La fonction n'est pas encore disponible.</p>
</div>
);
}
if (props.inputsArray.length <= 0) {
return (
<Fragment>
<form onSubmit={handleSubmit}>
{props.inputsArray.map((input, index) => {
switch (input.type) {
case "text":
return (
<div key={index} className="form-group">
<label className="form-label" htmlFor={input.name}>{input.label}</label>
<input onChange={handleChange} type="text" name={input.name} id={input.name} placeholder={input.placeholder} className="form-control" />
</div>
);
case "integer":
case "float":
return (
<div key={index} className="form-group">
<label className="form-label" htmlFor={input.name}>{input.label}</label>
<input onChange={handleChange} type="number" step={(input.type === "integer") ? "1" : "0.01"} name={input.name} id={input.name} placeholder={input.placeholder} className="form-control" />
</div>
);
case "calendar":
// Permet au datepicker de prendre la hauteur
if (typeof window != 'undefined') {
const newScript = document.createElement("script");
newScript.src = "/js/extraHeightCSS.js";
document.body.appendChild(newScript);
}
const DatePicker = dynamic(
() => import('react-datepicker'),
{ ssr: false }
);
return (
<div key={index} className="form-group">
<label className="form-label" htmlFor={input.name}>{input.label}</label>
<br/>
<DatePicker
selected={(() => {
try {
if (inputState[input.name] != undefined) {
const dateArray = inputState[input.name].split('/');
const year = dateArray[2];
const month = dateArray[1];
const day = dateArray[0];
return new Date(year, parseInt(month) - 1, parseInt(day) + 1);
}
throw "Not a valid date";
} catch {
return new Date();
}
})()}
locale="fr"
dateFormat="dd/MM/yyyy"
fixedHeight
placeholderText={input.placeholder}
onChange={(dateObject) => {
try {
const formattedDate = date.format(dateObject, 'DD/MM/YYYY', true);
handleChange({
target: {
name: input.name,
value: formattedDate
}
});
} catch {}
}}
/>
</div>
);
case "select":
return (
<div key={index} className="form-group">
<label className="form-label" htmlFor={input.name}>{input.label}</label>
<select onChange={handleChange} name={input.name} id={input.name} value={inputState[input.name] || input.options[0]} className="form-control">
{input.options.map((option, optionIndex) => {
return (
<option key={optionIndex} value={option.value}>{option.name}</option>
);
})}
</select>
</div>
);
default:
return (
<p>Erreur, l'input n'est pas valide...</p>
);
}
})}
<div className="form-group text-center">
<button type="submit" className="btn btn-dark">Envoyer</button>
<div className='FunctionComponent__slide text-center'>
<p>La fonction n'est pas encore disponible.</p>
</div>
)
}
return (
<>
<form onSubmit={handleSubmit}>
{props.inputsArray.map((input, index) => {
switch (input.type) {
case 'text':
return (
<div key={index} className='form-group'>
<label className='form-label' htmlFor={input.name}>{input.label}</label>
<input onChange={handleChange} type='text' name={input.name} id={input.name} placeholder={input.placeholder} className='form-control' />
</div>
</form>
<div className="form-result text-center">
{
(isLoading) ?
<Loader />
:
htmlParser(message)
}
</div>
</Fragment>
);
)
case 'integer':
case 'float':
return (
<div key={index} className='form-group'>
<label className='form-label' htmlFor={input.name}>{input.label}</label>
<input onChange={handleChange} type='number' step={(input.type === 'integer') ? '1' : '0.01'} name={input.name} id={input.name} placeholder={input.placeholder} className='form-control' />
</div>
)
case 'calendar':
// Permet au datepicker de prendre la hauteur
if (typeof window !== 'undefined') {
const newScript = document.createElement('script')
newScript.src = '/js/extraHeightCSS.js'
document.body.appendChild(newScript)
}
// eslint-disable-next-line
const DatePicker = dynamic(
() => import('react-datepicker'),
{ ssr: false }
)
return (
<div key={index} className='form-group'>
<label className='form-label' htmlFor={input.name}>{input.label}</label>
<br />
<DatePicker
selected={(() => {
try {
if (inputState[input.name] != null) {
const dateArray = inputState[input.name].split('/')
const year = dateArray[2]
const month = dateArray[1]
const day = dateArray[0]
return new Date(year, parseInt(month) - 1, parseInt(day) + 1)
}
throw new Error('Not a valid date')
} catch {
return new Date()
}
})()}
locale='fr'
dateFormat='dd/MM/yyyy'
fixedHeight
placeholderText={input.placeholder}
onChange={(dateObject) => {
try {
const formattedDate = date.format(dateObject, 'DD/MM/YYYY', true)
handleChange({
target: {
name: input.name,
value: formattedDate
}
})
} catch {}
}}
/>
</div>
)
case 'select':
return (
<div key={index} className='form-group'>
<label className='form-label' htmlFor={input.name}>{input.label}</label>
<select onChange={handleChange} name={input.name} id={input.name} value={inputState[input.name] || input.options[0]} className='form-control'>
{input.options.map((option, optionIndex) => {
return (
<option key={optionIndex} value={option.value}>{option.name}</option>
)
})}
</select>
</div>
)
default:
return (
<p>Erreur, l'input n'est pas valide...</p>
)
}
})}
<div className='form-group text-center'>
<button type='submit' className='btn btn-dark'>Envoyer</button>
</div>
</form>
<div className='form-result text-center'>
{
(isLoading)
? <Loader />
: htmlParser(message)
}
</div>
</>
)
}
export default FunctionForm;
export default FunctionForm

View File

@ -1,24 +1,23 @@
import { Fragment, useState } from 'react';
import { API_URL } from '../../utils/config/config';
import HeadTag from '../HeadTag';
import FunctionTabsTop from './FunctionTabsTop';
import FunctionComponentTop from './FunctionComponentTop';
import { useState } from 'react'
import { API_URL } from '../../utils/config/config'
import HeadTag from '../HeadTag'
import FunctionTabsTop from './FunctionTabsTop'
import FunctionComponentTop from './FunctionComponentTop'
const FunctionPage = (props) => {
const [slideIndex, setSlideIndex] = useState(0)
const [slideIndex, setSlideIndex] = useState(0);
return (
<>
<HeadTag title={props.title} description={props.description} image={API_URL + props.image} />
return (
<Fragment>
<HeadTag title={props.title} description={props.description} image={API_URL + props.image} />
<div className="container-fluid">
<FunctionTabsTop slideIndex={slideIndex} setSlideIndex={setSlideIndex} tabNames={props.tabNames} />
<FunctionComponentTop { ...props } />
<props.FunctionTabManager { ...props } slideIndex={slideIndex} setSlideIndex={setSlideIndex} />
</div>
</Fragment>
);
<div className='container-fluid'>
<FunctionTabsTop slideIndex={slideIndex} setSlideIndex={setSlideIndex} tabNames={props.tabNames} />
<FunctionComponentTop {...props} />
<props.FunctionTabManager {...props} slideIndex={slideIndex} setSlideIndex={setSlideIndex} />
</div>
</>
)
}
export default FunctionPage;
export default FunctionPage

View File

@ -1,14 +1,14 @@
import SwipeableViews from 'react-swipeable-views';
import './FunctionTabs.css';
import SwipeableViews from 'react-swipeable-views'
import './FunctionTabs.css'
const FunctionTabs = (props) => {
return (
<div className="container-fluid">
<SwipeableViews onChangeIndex={(index) => props.setSlideIndex(index)} index={props.slideIndex}>
{props.children}
</SwipeableViews>
</div>
);
return (
<div className='container-fluid'>
<SwipeableViews onChangeIndex={(index) => props.setSlideIndex(index)} index={props.slideIndex}>
{props.children}
</SwipeableViews>
</div>
)
}
export default FunctionTabs;
export default FunctionTabs

View File

@ -1,24 +1,24 @@
const FunctionTabsTop = (props) => {
return (
<div className="container">
<div className="row justify-content-center">
<ul className="FunctionTabs__nav">
{props.tabNames.map((tabName, index) => {
return (
<li key={index} className="FunctionTabs__nav-item">
<a
className={`FunctionTabs__nav-link ${(props.slideIndex === index) ? "FunctionTabs__nav-link-active" : ""}`}
onClick={() => props.setSlideIndex(index)}
>
{tabName}
</a>
</li>
);
})}
</ul>
</div>
</div>
);
return (
<div className='container'>
<div className='row justify-content-center'>
<ul className='FunctionTabs__nav'>
{props.tabNames.map((tabName, index) => {
return (
<li key={index} className='FunctionTabs__nav-item'>
<a
className={`FunctionTabs__nav-link ${(props.slideIndex === index) ? 'FunctionTabs__nav-link-active' : ''}`}
onClick={() => props.setSlideIndex(index)}
>
{tabName}
</a>
</li>
)
})}
</ul>
</div>
</div>
)
}
export default FunctionTabsTop;
export default FunctionTabsTop