Skip to content

Commit

Permalink
Merge pull request #263 from Sterbenfr/fix/app
Browse files Browse the repository at this point in the history
fix(app): Fixed inputs lag and select in popup
  • Loading branch information
Aurelienschmi authored Jul 31, 2024
2 parents 5811a59 + b81b40f commit 2116444
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 81 deletions.
24 changes: 9 additions & 15 deletions app/api/sites/[siteID]/interlocuteurs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export async function GET(
const offset = (pageNumber - 1) * limitNumber

const [rows] = await connection.query(
'SELECT * FROM `Interlocuteurs` LEFT JOIN SitesRattachement ON Interlocuteurs.code_interlocuteur = SitesRattachement.code_interlocuteur WHERE SitesRattachement.code_site = ? LIMIT ?, ?',
'SELECT * FROM `Interlocuteurs` WHERE code_site = ? LIMIT ?, ?',
[siteID, offset, limitNumber],
)

const [totalResult] = await connection.query(
'SELECT COUNT(*) as count FROM `Interlocuteurs` LEFT JOIN SitesRattachement ON Interlocuteurs.code_interlocuteur = SitesRattachement.code_interlocuteur WHERE SitesRattachement.code_site = ?',
'SELECT COUNT(*) as count FROM `Interlocuteurs` WHERE code_site = ?',
[siteID],
)

Expand All @@ -48,9 +48,8 @@ export async function GET(
}
}

type extendedInterlocuteurs = Interlocuteurs & { code_site: string }
export async function POST(req: NextRequest) {
let Interlocuteur: extendedInterlocuteurs
let Interlocuteur: Interlocuteurs
try {
Interlocuteur = JSON.parse(await streamToString(req.body))
} catch (error) {
Expand All @@ -62,25 +61,20 @@ export async function POST(req: NextRequest) {
!Interlocuteur.civilite ||
!Interlocuteur.nom ||
!Interlocuteur.prenom ||
!Interlocuteur.code_type_utilisateur
!Interlocuteur.code_type_interlocuteur
) {
return NextResponse.json(
{ error: 'Missing product data' },
{ status: 400 },
)
}
const { code_site, ...user } = Interlocuteur
try {
const query = 'INSERT INTO `Interlocuteurs` SET ?'
const [result] = await connection.query<ResultSetHeader>(query, user)
const query2 =
'INSERT INTO `SitesRattachement` SET code_interlocuteur = ?, code_site = ?, code_type_utilisateur = ?'
const [rows2] = await connection.query(query2, [
result.insertId,
code_site,
Interlocuteur.code_type_utilisateur,
])
return NextResponse.json({ result, rows2 })
const [result] = await connection.query<ResultSetHeader>(
query,
Interlocuteur,
)
return NextResponse.json({ result })
} catch (error) {
return NextResponse.json(
{ error: 'Internal Server Error : ' + error },
Expand Down
11 changes: 8 additions & 3 deletions app/dons/[donsID]/modalites-livraison/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,9 @@ function ModalitesLivraisonPage({ params }: { params: { donsID: string } }) {
if (fields[FindIndex('nombre_cartons_prevu')].value === '') {
fields[FindIndex('nombre_cartons_prevu')].value = null
}
if (fields[FindIndex('nombre_palettes_consignees_prevu')].value === '') {
if (
fields[FindIndex('nombre_palettes_consignees_prevu')].value === ''
) {
fields[FindIndex('nombre_palettes_consignees_prevu')].value = null
}
if (fields[FindIndex('nombre_palettes_prevu')].value === '') {
Expand Down Expand Up @@ -601,7 +603,6 @@ function ModalitesLivraisonPage({ params }: { params: { donsID: string } }) {
}: { data: ModalitesLivraison[]; total: number } = await res.json()
setModalitesLivraison(data)
setTotalItems(total)
setFields(generateFields())
}

const fetchSearchModalitesLivraisons = async () => {
Expand All @@ -623,7 +624,11 @@ function ModalitesLivraisonPage({ params }: { params: { donsID: string } }) {
fetchModalitesLivraisons()
fetchSearchModalitesLivraisons()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [page, itemsPerPage, params.donsID, generateFields])
}, [page, itemsPerPage, params.donsID])

useEffect(() => {
setFields(generateFields())
}, [generateFields])

const handlePageChange = (newPage: number) => {
setPage(newPage)
Expand Down
7 changes: 5 additions & 2 deletions app/dons/[donsID]/reception/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ function ReceptionsPage({ params }: { params: { donsID: string } }) {
await res.json()
setReceptions(data)
setTotalItems(total)
setFields(generateFields())
}

const fetchSearchDons = async () => {
Expand All @@ -356,7 +355,11 @@ function ReceptionsPage({ params }: { params: { donsID: string } }) {

fetchDons()
fetchSearchDons()
}, [page, itemsPerPage, params.donsID, generateFields, search])
}, [page, itemsPerPage, params.donsID, search])

useEffect(() => {
setFields(generateFields())
}, [generateFields])

// add a function to handle page changes
const handlePageChange = (newPage: number) => {
Expand Down
24 changes: 13 additions & 11 deletions app/dons/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,6 @@ function DonsPage() {
await res.json()
setDons(data)
setTotalItems(total) // set the total items
setFields(
generateFields(
debutMiseDispo,
finMiseDispo,
selectedTypeDon,
selectedTypeMarchandise,
commentaires,
statutAcceptationDon,
),
)
}

const fetchSearchDons = async () => {
Expand All @@ -618,9 +608,21 @@ function DonsPage() {
selectedTypeMarchandise,
statutAcceptationDon,
debutMiseDispo,
generateFields,
])

useEffect(() => {
setFields(
generateFields(
debutMiseDispo,
finMiseDispo,
selectedTypeDon,
selectedTypeMarchandise,
commentaires,
statutAcceptationDon,
),
)
}, [generateFields])

const handlePageChange = (newPage: number) => {
setPage(newPage)
}
Expand Down
7 changes: 5 additions & 2 deletions app/prestataire/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ function PrestatairesPage() {
await res.json()
setPrestataires(data)
setTotalItems(total)
setFields(generateFields())
}

const fetchSearchDons = async () => {
Expand All @@ -342,7 +341,11 @@ function PrestatairesPage() {

fetchDons()
fetchSearchDons()
}, [page, itemsPerPage, generateFields, search])
}, [page, itemsPerPage, search])

useEffect(() => {
setFields(generateFields())
}, [generateFields])

const handlePageChange = (newPage: number) => {
setPage(newPage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface ExtendedSession extends Session {

interface InterlocuteurID {
code_interlocuteur: number
code_site: number
civilite: string
nom: string
prenom: string
Expand Down
15 changes: 9 additions & 6 deletions app/sites/[siteID]/interlocuteurs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import Image from 'next/image'

export interface Interlocuteurs {
code_interlocuteur: number
code_site: number
civilite: string
nom: string
prenom: string
tel_perso: string
mail: string
commentaires: string
code_type_utilisateur: number
code_type_interlocuteur: number
}

function InterlocuteursPage({ params }: { params: { siteID: string } }) {
Expand Down Expand Up @@ -148,11 +149,11 @@ function InterlocuteursPage({ params }: { params: { siteID: string } }) {
},

{
id: 'code_type_utilisateur',
id: 'code_type_interlocuteur',
type: 'select',
required: true,
value: codeTypeUtilisateur,
url: `../../../../../api/select/utilisateurs`,
url: `../../../../../api/sites/${params.siteID}/interlocuteurs/type-interlocuteur`,
onChange: handleCodeTypeUtilisateurChange,
},
{
Expand Down Expand Up @@ -215,7 +216,6 @@ function InterlocuteursPage({ params }: { params: { siteID: string } }) {
await res.json()
setInterlocuteurs(data)
setTotalItems(total) // set the total items
setFields(generateFields())
}

const fetchSearchInterlocuteurs = async () => {
Expand All @@ -236,7 +236,11 @@ function InterlocuteursPage({ params }: { params: { siteID: string } }) {
fetchInterlocuteurs()
fetchSearchInterlocuteurs()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [page, itemsPerPage, params.siteID, generateFields])
}, [page, itemsPerPage, params.siteID])

useEffect(() => {
setFields(generateFields())
}, [generateFields])

// add a function to handle page changes
const handlePageChange = (newPage: number) => {
Expand Down Expand Up @@ -334,7 +338,6 @@ function InterlocuteursPage({ params }: { params: { siteID: string } }) {
{
label: `Types d'interlocuteurs`,
url: 'type-interlocuteur',

},
]}
/>
Expand Down
16 changes: 10 additions & 6 deletions app/sites/[siteID]/interlocuteurs/type-interlocuteur/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export interface type_interlocuteur {
}

function InterlocuteursPage({ params }: { params: { siteID: string } }) {
const [Interlocuteurs, setInterlocuteurs] = useState<type_interlocuteur[]>([])
const [Interlocuteurs, setInterlocuteurs] = useState<type_interlocuteur[]>(
[],
)

const [isPopUpOpen, setIsPopUpOpen] = useState(false)

Expand All @@ -24,7 +26,7 @@ function InterlocuteursPage({ params }: { params: { siteID: string } }) {
const fetchInterlocuteurs = async () => {
if (!params.siteID) return
const res = await fetch(
`../../../../api/sites/${params.siteID}/interlocuteurs/type-interlocuteurs`,
`../../../../api/sites/${params.siteID}/interlocuteurs/type-interlocuteur`,
)

if (!res.ok) {
Expand All @@ -42,7 +44,9 @@ function InterlocuteursPage({ params }: { params: { siteID: string } }) {
<>
<div className={style.page}>
<div className={style.croixID}>
<h1 className={style.lg1}>Types d&apos;utilisateurs</h1>
<h1 className={style.lg1}>
Types d&apos;interlocuteurs RC
</h1>
<a href='javascript:history.go(-1)' className={style.btnC}>
<Image
className={style.CR}
Expand All @@ -66,7 +70,7 @@ function InterlocuteursPage({ params }: { params: { siteID: string } }) {
? setIsPopUpOpen(false)
: setIsPopUpOpen(true)
},
url: `../../../../api/sites/${params.siteID}/interlocuteurs/type-interlocuteurs`,
url: `../../../../api/sites/${params.siteID}/interlocuteurs/type-interlocuteur`,
}}
attribut={{
att1: 'Code',
Expand All @@ -77,10 +81,10 @@ function InterlocuteursPage({ params }: { params: { siteID: string } }) {
<div className={style.PopUpType}>
<PopUp
onClose={handleClose}
url={`../../../../api/sites/${params.siteID}/interlocuteurs/type-interlocuteurs`}
url={`../../../../api/sites/${params.siteID}/interlocuteurs/type-interlocuteur`}
fields={[
{
id: 'code_type_utilisateur',
id: 'code_type_interlocuteur',
type: 'input',
value: null,
required: true,
Expand Down
14 changes: 5 additions & 9 deletions app/sites/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ function SitesPage() {
await res.json()
setSites(data)
setTotalItems(total)
setFields(generateFields())
}

const fetchSearchSites = async () => {
Expand All @@ -270,14 +269,11 @@ function SitesPage() {

fetchSites()
fetchSearchSites()
}, [
page,
itemsPerPage,
generateFields,
dateOuverture,
dateFermeture,
search,
])
}, [page, itemsPerPage, dateOuverture, dateFermeture, search])

useEffect(() => {
setFields(generateFields())
}, [generateFields])

const handlePageChange = (newPage: number) => {
setPage(newPage)
Expand Down
14 changes: 5 additions & 9 deletions app/societe/[societeID]/entite/[entiteID]/contact/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ function ContactsPage({
await res.json()
setContacts(data)
setTotalItems(total) // set the total items
setFields(generateFields())
}

const fetchSearchContacts = async () => {
Expand All @@ -288,14 +287,11 @@ function ContactsPage({

fetchContacts()
fetchSearchContacts()
}, [
params.societeID,
params.entiteID,
page,
itemsPerPage,
search,
generateFields,
])
}, [params.societeID, params.entiteID, page, itemsPerPage, search])

useEffect(() => {
setFields(generateFields())
}, [generateFields])

// add a function to handle page changes
const handlePageChange = (newPage: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,14 @@ function ContactEntitePage({
await res.json()
setContacts(data)
setTotalItems(total)
setFields(generateFields())
}

fetchContacts()
}, [page, itemsPerPage, params, generateFields])
}, [page, itemsPerPage, params])

useEffect(() => {
setFields(generateFields())
}, [generateFields])

const handlePageChange = (newPage: number) => {
setPage(newPage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ function InteractionsPage({
await res.json()
setInteractions(data)
setTotalItems(total)
setFields(generateFields())
}

const fetchSearchInteractions = async () => {
Expand All @@ -250,7 +249,12 @@ function InteractionsPage({
fetchInteractions()
fetchSearchInteractions()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [page, itemsPerPage, params.societeID, params.entiteID, generateFields])
}, [page, itemsPerPage, params.societeID, params.entiteID])

useEffect(() => {
setFields(generateFields())
}, [generateFields])

// add a function to handle page changes
const handlePageChange = (newPage: number) => {
setPage(newPage)
Expand Down
Loading

0 comments on commit 2116444

Please sign in to comment.