Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prof21
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
TALENT
TALENT
prof21
Commits
a67e297f
Commit
a67e297f
authored
3 years ago
by
mperezsa
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
8956d816
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
PROF-XXI FW Tool/client/src/components/pages/ManageUnit.js
+260
-0
260 additions, 0 deletions
PROF-XXI FW Tool/client/src/components/pages/ManageUnit.js
with
260 additions
and
0 deletions
PROF-XXI FW Tool/client/src/components/pages/ManageUnit.js
0 → 100644
+
260
−
0
View file @
a67e297f
import
React
,
{
useState
,
useEffect
}
from
"
react
"
;
import
{
Link
,
useLocation
}
from
"
react-router-dom
"
;
import
Footer
from
"
../../components/Footer
"
;
import
"
./Default.css
"
;
import
axios
from
"
axios
"
;
function
ManageUnit
()
{
const
[
unit
,
setUnit
]
=
useState
({
unitId
:
""
,
unitName
:
""
,
unitType
:
""
,
unitDescription
:
""
,
accessType
:
""
,
});
const
[
units
,
setUnits
]
=
useState
([]);
const
[
text
,
setText
]
=
useState
(
""
);
const
[
toggleConfirmation
,
setToggleConfirmation
]
=
useState
(
false
);
const
[
profile
,
setProfile
]
=
useState
(
JSON
.
parse
(
localStorage
.
getItem
(
"
profile
"
))
);
const
location
=
useLocation
();
const
config
=
{
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
Authorization
:
`Bearer
${
profile
.
token
}
`
,
},
};
const
handleChange
=
(
e
)
=>
{
const
fieldName
=
e
.
target
.
name
;
const
fieldValue
=
e
.
target
.
value
;
setUnit
({
...
unit
,
[
fieldName
]:
fieldValue
});
};
const
handleUpdate
=
async
(
e
)
=>
{
e
.
preventDefault
();
if
(
!
(
unit
.
unitId
===
""
))
{
const
{
data
}
=
await
axios
.
put
(
`/api/units/manageunit/update/
${
unit
.
unitId
}
`
,
{
unit
:
unit
,
},
config
);
setText
(
data
.
message
);
}
else
{
setText
(
"
Please select a unit
"
);
}
};
const
handleConfirmation
=
(
e
)
=>
{
if
(
!
(
unit
.
unitId
===
""
))
{
if
(
!
toggleConfirmation
)
{
setToggleConfirmation
(
true
);
setText
(
"
We inform you that all the data assigned to the selected unit are going to be deleted, Do you still want to continue with this process ?
"
);
}
else
{
setToggleConfirmation
(
false
);
setText
(
""
);
}
}
else
{
setText
(
"
Please select a unit
"
);
}
};
const
handleDelete
=
async
(
e
)
=>
{
e
.
preventDefault
();
const
{
data
}
=
await
axios
.
delete
(
`/api/units/manageunit/delete/
${
unit
.
unitId
}
`
,
config
,
{
unitId
:
unit
.
unitId
,
}
);
setText
(
data
.
message
);
};
const
fetchData
=
async
(
e
)
=>
{
const
{
data
}
=
await
axios
.
get
(
"
/api/units/manageunit
"
,
config
);
setUnits
(
data
.
unitsResult
);
};
const
fetchCurrentUnit
=
async
()
=>
{
units
.
map
((
element
)
=>
{
if
(
`
${
element
.
idunit
}
`
===
unit
.
unitId
)
{
setUnit
({
unitId
:
unit
.
unitId
,
unitName
:
element
.
name
,
unitType
:
element
.
type
,
unitDescription
:
element
.
description
,
accessType
:
element
.
access
,
});
}
});
};
useEffect
(()
=>
{
document
.
title
=
"
Manage your units
"
;
setProfile
(
JSON
.
parse
(
localStorage
.
getItem
(
"
profile
"
)));
if
(
!
profile
?.
token
)
{
window
.
location
=
"
/login
"
;
}
fetchData
();
fetchCurrentUnit
();
},
[
location
,
unit
.
unitId
]);
return
(
<>
<
h2
>
Manage
your
unit
of
Analysis
<
/h2
>
<
div
className
=
"
middle-container
"
>
<
article
className
=
"
form
"
>
<
form
>
<
div
>
<
label
htmlFor
=
"
unit
"
>
Change
Unit
:
<
/label
>
<
select
id
=
"
unitId
"
name
=
"
unitId
"
value
=
{
unit
.
unitId
}
onChange
=
{
handleChange
}
>
<
option
>
Select
your
unit
Please
<
/option
>
{
units
?.
map
((
unit
)
=>
(
<
option
key
=
{
unit
.
idunit
}
value
=
{
unit
.
idunit
}
>
{
unit
.
name
}
<
/option
>
))}
<
/select
>
<
/div
>
<
div
>
<
label
htmlFor
=
"
unitName
"
>
Name
of
unit
of
Analysis
:
<
/label
>
<
input
type
=
"
text
"
id
=
"
unitName
"
name
=
"
unitName
"
value
=
{
unit
.
unitName
}
onChange
=
{
handleChange
}
/
>
<
/div
>
<
div
>
<
label
htmlFor
=
"
unitType
"
>
Type
of
your
unit
:
<
/label
>
<
select
id
=
"
unitType
"
name
=
"
unitType
"
value
=
{
unit
.
unitType
}
onChange
=
{
handleChange
}
>
<
option
>
Select
your
type
<
/option
>
<
option
value
=
"
Computer Science
"
>
Computer
Science
<
/option
>
<
option
value
=
"
Mechanics
"
>
Mechanics
<
/option
>
<
option
value
=
"
Electronics
"
>
Electronics
<
/option
>
<
option
value
=
"
Aerodynamics
"
>
Aerodynamics
<
/option
>
<
option
value
=
"
Civil Engineering
"
>
Civil
engineering
<
/option
>
<
option
value
=
"
Library
"
>
Library
<
/option
>
<
option
value
=
"
Biology
"
>
Biology
<
/option
>
<
option
value
=
"
Medecine
"
>
Medecine
<
/option
>
<
option
value
=
"
Litterature
"
>
Economics
<
/option
>
<
option
value
=
"
Management
"
>
Management
<
/option
>
<
option
value
=
"
Mathematics
"
>
Mathematics
<
/option
>
<
option
value
=
"
Physics
"
>
Physics
<
/option
>
<
option
value
=
"
Law
"
>
Law
<
/option
>
<
option
value
=
"
History
"
>
History
<
/option
>
<
option
value
=
"
Arts
"
>
Arts
<
/option
>
<
/select
>
<
/div
>
<
div
>
Other
Type
:
<
input
type
=
"
text
"
id
=
"
unitType
"
name
=
"
unitType
"
value
=
{
unit
.
unitType
}
onChange
=
{
handleChange
}
/
>
<
/div
>
<
label
htmlFor
=
"
unitDescription
"
>
Description
of
unit
:
<
/label
>
<
div
>
<
textarea
name
=
"
unitDescription
"
id
=
"
unitDescription
"
value
=
{
unit
.
unitDescription
}
onChange
=
{
handleChange
}
cols
=
"
50
"
rows
=
"
5
"
><
/textarea
>
<
/div
>
<
div
>
<
label
htmlFor
=
"
accessType
"
>
Type
of
Access
<
/label
>
<
select
id
=
"
accessType
"
name
=
"
accessType
"
value
=
{
unit
.
accessType
}
onChange
=
{
handleChange
}
>
<
option
defaultValue
=
"
Public
"
>
Public
<
/option
>
<
option
value
=
"
Private
"
>
Private
<
/option
>
<
/select
>
<
/div
>
<
div
>
<
button
type
=
"
submit
"
className
=
"
btn
"
onClick
=
{
handleUpdate
}
>
Save
Modifications
<
/button
>
<
Link
to
=
"
/workingarea
"
>
<
button
className
=
"
btn
"
>
Working
Area
<
/button
>
<
/Link
>
<
/div
>
<
/form
>
<
div
>
<
button
className
=
"
btn
"
onClick
=
{
handleConfirmation
}
>
Delete
Unit
<
/button
>
<
/div
>
<
h4
style
=
{{
color
:
"
red
"
,
marginTop
:
"
2rem
"
}}
>
{
text
}
<
/h4
>
{
toggleConfirmation
&&
(
<>
<
div
>
<
button
style
=
{{
backgroundColor
:
"
red
"
}}
className
=
"
btn
"
onClick
=
{
handleDelete
}
>
Continue
!
<
/button
>
<
button
style
=
{{
backgroundColor
:
"
orange
"
}}
className
=
"
btn
"
onClick
=
{
handleConfirmation
}
>
Abondon
Deleting
<
/button
>
<
/div
>
<
/
>
)}
<
/article
>
<
img
style
=
{{
marginLeft
:
"
10rem
"
}}
width
=
"
50%
"
height
=
"
50%
"
src
=
"
images/design7.jpg
"
alt
=
""
/>
<
/div
>
<
Footer
/>
<
/
>
);
}
export
default
ManageUnit
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment