Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gestion des stages Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fatima Ezzahra Majidi
Gestion des stages Frontend
Merge requests
!7
candidater avec l'id de l'étudiant dans la session
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
candidater avec l'id de l'étudiant dans la session
master
into
main
Overview
0
Commits
1
Pipelines
0
Changes
4
Merged
Fatima Ezzahra Majidi
requested to merge
master
into
main
3 months ago
Overview
0
Commits
1
Pipelines
0
Changes
4
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
069e858a
1 commit,
3 months ago
4 files
+
179
−
11
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
src/components/Candidatures/CandidacyFormPrerempli.jsx
0 → 100644
+
137
−
0
Options
import
React
,
{
useState
,
useEffect
}
from
"
react
"
;
import
{
Navigate
}
from
"
react-router-dom
"
;
const
CandidacyFormPrerempli
=
()
=>
{
const
[
students
,
setStudents
]
=
useState
([]);
const
[
stages
,
setStages
]
=
useState
([]);
const
[
supervisors
,
setSupervisors
]
=
useState
([]);
// ✅ Initialise formData avec un studentId vide (sera mis à jour ensuite)
const
[
formData
,
setFormData
]
=
useState
({
studentId
:
""
,
stageId
:
""
,
univSupervisorId
:
""
,
});
/** 🔹 Charge le studentId à partir du localStorage */
useEffect
(()
=>
{
const
storedUser
=
JSON
.
parse
(
localStorage
.
getItem
(
"
user
"
));
if
(
storedUser
&&
storedUser
.
username
&&
storedUser
.
familyname
)
{
setFormData
((
prevFormData
)
=>
({
...
prevFormData
,
studentId
:
storedUser
.
id
||
""
,
// ✅ Vérifie que l'ID existe
}));
}
},
[]);
/** 🔹 Charge les étudiants avec rôle ETUDIANT (si besoin) */
useEffect
(()
=>
{
fetch
(
"
http://localhost:8080/api/students/with-role
"
)
.
then
((
res
)
=>
res
.
json
())
.
then
((
data
)
=>
setStudents
(
data
))
.
catch
((
err
)
=>
console
.
error
(
"
❌ Erreur lors du chargement des étudiants :
"
,
err
));
},
[]);
/** 🔹 Charge les stages */
useEffect
(()
=>
{
fetch
(
"
http://localhost:8080/api/stages
"
)
.
then
((
res
)
=>
res
.
json
())
.
then
((
data
)
=>
setStages
(
data
));
},
[]);
/** 🔹 Charge les superviseurs */
useEffect
(()
=>
{
fetch
(
"
http://localhost:8080/api/univsupervisors
"
)
.
then
((
res
)
=>
res
.
json
())
.
then
((
data
)
=>
setSupervisors
(
data
));
},
[]);
const
handleChange
=
(
e
)
=>
{
setFormData
({
...
formData
,
[
e
.
target
.
name
]:
e
.
target
.
value
});
};
const
handleSubmit
=
(
e
)
=>
{
e
.
preventDefault
();
const
candidacyData
=
{
student
:
{
id
:
formData
.
studentId
},
stage
:
{
id
:
formData
.
stageId
},
univSupervisor
:
{
id
:
formData
.
univSupervisorId
},
};
console
.
log
(
"
📌 Sending Candidacy Data:
"
,
JSON
.
stringify
(
candidacyData
,
null
,
2
));
fetch
(
"
http://localhost:8080/api/candidacies/add
"
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
credentials
:
"
include
"
,
body
:
JSON
.
stringify
(
candidacyData
),
})
.
then
((
res
)
=>
{
console
.
log
(
"
📌 Response status:
"
,
res
.
status
);
return
res
.
json
();
})
.
then
((
data
)
=>
{
console
.
log
(
"
✅ Candidacy added successfully:
"
,
data
);
alert
(
"
Candidature ajoutée avec succès !
"
);
})
.
catch
((
err
)
=>
console
.
error
(
"
❌ Error:
"
,
err
.
message
));
};
return
(
<
div
className
=
"container mt-4"
>
<
h2
>
Ajouter ma Candidature
</
h2
>
<
form
onSubmit
=
{
handleSubmit
}
>
{
/* ✅ Student (prérempli, non modifiable) */
}
<
div
className
=
"mb-3"
>
<
label
className
=
"form-label"
>
Étudiant:
</
label
>
<
input
type
=
"text"
className
=
"form-control"
value
=
{
`
${
localStorage
.
getItem
(
"
username
"
)
||
""
}
${
localStorage
.
getItem
(
"
familyname
"
)
||
""
}
`
}
disabled
/>
</
div
>
{
/* Select Stage */
}
<
div
className
=
"mb-3"
>
<
label
className
=
"form-label"
>
Stage:
</
label
>
<
select
className
=
"form-control"
name
=
"stageId"
value
=
{
formData
.
stageId
}
onChange
=
{
handleChange
}
required
>
<
option
value
=
""
>
Sélectionnez un stage
</
option
>
{
stages
.
map
((
stage
)
=>
(
<
option
key
=
{
stage
.
id
}
value
=
{
stage
.
id
}
>
{
stage
.
name
}
-
{
stage
.
description
}
</
option
>
))
}
</
select
>
</
div
>
{
/* Select UnivSupervisor */
}
<
div
className
=
"mb-3"
>
<
label
className
=
"form-label"
>
Superviseur Universitaire:
</
label
>
<
select
className
=
"form-control"
name
=
"univSupervisorId"
value
=
{
formData
.
univSupervisorId
}
onChange
=
{
handleChange
}
required
>
<
option
value
=
""
>
Sélectionnez un superviseur
</
option
>
{
supervisors
.
map
((
supervisor
)
=>
(
<
option
key
=
{
supervisor
.
id
}
value
=
{
supervisor
.
id
}
>
{
supervisor
.
name
}
</
option
>
))
}
</
select
>
</
div
>
<
div
className
=
"d-flex gap-2"
>
<
button
type
=
"submit"
className
=
"btn btn-primary"
>
Ajouter Candidature
</
button
>
<
button
type
=
"button"
className
=
"btn btn-secondary"
onClick
=
{
()
=>
Navigate
(
"
/candidatures
"
)
}
>
Annuler
</
button
>
</
div
>
</
form
>
</
div
>
);
};
export
default
CandidacyFormPrerempli
;
Loading