From e1a8c90f3e1f348c1e2a1defb26ec296f614fbf2 Mon Sep 17 00:00:00 2001 From: Thibaut Valentin Date: Sat, 13 Jul 2024 22:42:04 +0200 Subject: [PATCH] wip: club end main --- .../src/components/MemberCustomFiels.jsx | 4 +- .../webapp/src/pages/admin/club/ClubPage.jsx | 184 ++++++++++++++---- .../src/pages/admin/club/LocationEditor.jsx | 64 +++--- 3 files changed, 192 insertions(+), 60 deletions(-) diff --git a/src/main/webapp/src/components/MemberCustomFiels.jsx b/src/main/webapp/src/components/MemberCustomFiels.jsx index fff6053..d03e69f 100644 --- a/src/main/webapp/src/components/MemberCustomFiels.jsx +++ b/src/main/webapp/src/components/MemberCustomFiels.jsx @@ -57,12 +57,12 @@ export function CountryList({name, text, value, values = undefined, disabled = f return } -export function TextField({name, text, value, placeholder, type = "text", disabled = false}) { +export function TextField({name, text, value, placeholder, type = "text", disabled = false, required = true}) { return
{text} + name={name} aria-describedby={name} defaultValue={value} disabled={disabled} required={required}/>
} diff --git a/src/main/webapp/src/pages/admin/club/ClubPage.jsx b/src/main/webapp/src/pages/admin/club/ClubPage.jsx index 32c0a66..a067e7c 100644 --- a/src/main/webapp/src/pages/admin/club/ClubPage.jsx +++ b/src/main/webapp/src/pages/admin/club/ClubPage.jsx @@ -8,14 +8,11 @@ import {AxiosError} from "../../../components/AxiosError.jsx"; import {AffiliationCard} from "./AffiliationCard.jsx"; import {CheckField, CountryList, TextField} from "../../../components/MemberCustomFiels.jsx"; -import {MapContainer, Marker, Popup, TileLayer, useMap} from 'react-leaflet' -import {ListEditorTest} from "../../../components/ListEditor.jsx"; import {useEffect, useReducer, useRef, useState} from "react"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faPen, faTrashCan} from "@fortawesome/free-solid-svg-icons"; -import proj4 from "proj4"; import {SimpleReducer} from "../../../utils/SimpleReducer.jsx"; -import {LocationEditor} from "./LocationEditor.jsx"; +import {LocationEditor, LocationEditorModal} from "./LocationEditor.jsx"; const vite_url = import.meta.env.VITE_URL; @@ -71,43 +68,82 @@ export function ClubPage() { } function InformationForm({data}) { - return
-
Licence n°{data.no_affiliation}
-
+ const [switchOn, setSwitchOn] = useState(data.international); + const [modal, setModal] = useState({id: -1}) + const locationModalCallback = useRef(null) - - - - - - avatar + const handleSubmit = (event) => { + event.preventDefault(); -
-
- - + const formData = new FormData(event.target); + + toast.promise( + apiAxios.post(`/club/${data.id}`, formData), + { + pending: "Enregistrement du club en cours", + success: "Club enregistrée avec succès 🎉", + error: "Échec de l'enregistrement du club 😕" + } + ) + } + + return <> +
+
+
Licence n°{data.no_affiliation}
+
+ + + + + avatar + +
+
+ + +
+
Laissez vide pour ne rien changer.
+
+ +
+
+ setSwitchOn(!switchOn)}/> +
+ +
+ {!switchOn && <> + + + + + + + + + + } +
+
+
+ +
-
Laissez vide pour ne rien changer.
+
- - - - - - - - -
-
; + + } export function ContactEditor({data}) { const [state, dispatch] = useReducer(SimpleReducer, []) + const [out_data, setOutData] = useState({}) useEffect(() => { for (const key in data.contact) { @@ -115,9 +151,19 @@ export function ContactEditor({data}) { } }, [data.contact]); + useEffect(() => { + let out_data2 = {} + state.forEach(d => { + if (d.data !== undefined) + out_data2[d.id] = d.data + }) + setOutData(out_data2) + }, [state]); + return
+ + Contacts
- Contact
    {state.map((d, index) => { if (d.data === undefined) @@ -152,4 +198,76 @@ export function ContactEditor({data}) {
+} + +function timeNumberToSting(nbMin) { + return String(Math.floor(nbMin / 60)).padStart(2, '0') + ":" + String(nbMin % 60).padStart(2, '0') +} + +function timeStringToNumber(time) { + let times = time.split(':'); + return parseInt(times[0]) * 60 + parseInt(times[1]); +} + +export function HoraireEditor({data}) { + const [state, dispatch] = useReducer(SimpleReducer, []) + const [out_data, setOutData] = useState({}) + + useEffect(() => { + if (data.training_day_time === null) + return + JSON.parse(data.training_day_time).forEach((d, index) => { + dispatch({type: 'UPDATE_OR_ADD', payload: {id: index, data: d}}) + }) + }, [data.training_day_time]); + + useEffect(() => { + setOutData(state.map(d => { + return {day: d.data.day, time_start: d.data.time_start, time_end: d.data.time_end} + })) + }, [state]); + + return
+ + Horaires d'entrainements +
+
    + {state.map((d, index) => { + return
    +
    + + de + { + d.data.time_start = timeStringToNumber(e.target.value) + dispatch({type: 'UPDATE_OR_ADD', payload: {id: d.id, data: d.data}}) + }}/> + à + { + d.data.time_end = timeStringToNumber(e.target.value) + dispatch({type: 'UPDATE_OR_ADD', payload: {id: d.id, data: d.data}}) + }}/> + +
    +
    + })} +
+
+
} \ No newline at end of file diff --git a/src/main/webapp/src/pages/admin/club/LocationEditor.jsx b/src/main/webapp/src/pages/admin/club/LocationEditor.jsx index 4ccb5af..948649d 100644 --- a/src/main/webapp/src/pages/admin/club/LocationEditor.jsx +++ b/src/main/webapp/src/pages/admin/club/LocationEditor.jsx @@ -6,9 +6,9 @@ import {useFetch} from "../../../hooks/useFetch.js"; import {MapContainer, Marker, TileLayer} from "react-leaflet"; import {SimpleReducer} from "../../../utils/SimpleReducer.jsx"; -export function LocationEditor({data}) { - const [modal, setModal] = useState({id: -1}) +export function LocationEditor({data, setModal, sendData}) { const [state, dispatch] = useReducer(SimpleReducer, []) + const [out_data, setOutData] = useState({}) useEffect(() => { if (data.training_location === null) @@ -18,7 +18,7 @@ export function LocationEditor({data}) { }) }, [data.training_location]); - const sendAffiliation = (e) => { + sendData.current = (e) => { e.preventDefault(); const formData = new FormData(e.target); @@ -34,15 +34,25 @@ export function LocationEditor({data}) { }) } + useEffect(() => { + setOutData(state.map(d => { + return {text: d.data.text, lat: d.data.lat, lng: d.data.lng} + })) + }, [state]); + return
+ + Lieux d'entrainements
- Lieux d'entrainement
    {state.map((d, index) => { return
    {d.data.text}
    })}
- +} + +export function LocationEditorModal({modal, sendData}) { + return
}