Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COM3014
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Abdelsamad, Mouaz R (UG - SISC)
COM3014
Commits
bbed87bc
Commit
bbed87bc
authored
11 months ago
by
lcross2002
Browse files
Options
Downloads
Patches
Plain Diff
Wired up update user form
parent
4a576de9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/src/components/Dashboard/Profile/Profile.tsx
+30
-4
30 additions, 4 deletions
client/src/components/Dashboard/Profile/Profile.tsx
client/src/services/PatchUser/PatchUser.ts
+10
-0
10 additions, 0 deletions
client/src/services/PatchUser/PatchUser.ts
with
40 additions
and
4 deletions
client/src/components/Dashboard/Profile/Profile.tsx
+
30
−
4
View file @
bbed87bc
import
{
useState
}
from
'
react
'
;
import
{
useForm
}
from
'
react-hook-form
'
;
import
{
AxiosError
}
from
'
axios
'
;
import
{
useAuth
}
from
'
../../../hooks/useAuth
'
;
import
avatar
from
'
./avatar.jpg
'
;
import
plane
from
'
./airplane.jpg
'
;
import
{
patchUser
}
from
'
../../../services/PatchUser/PatchUser
'
;
import
'
./Profile.scss
'
;
interface
IProfileForm
{
export
interface
IProfileForm
{
name
:
string
;
email
:
string
;
password
:
string
;
...
...
@@ -13,7 +15,7 @@ interface IProfileForm {
}
function
Profile
()
{
const
{
user
}
=
useAuth
();
const
{
user
,
updateUser
}
=
useAuth
();
const
[
disabled
,
setDisabled
]
=
useState
(
true
);
const
[
error
,
setError
]
=
useState
(
''
);
const
isAirline
=
user
?.
type
===
1
;
...
...
@@ -46,7 +48,7 @@ function Profile() {
resetFormValues
();
};
const
onSubmit
=
(
formValue
:
IProfileForm
)
=>
{
const
onSubmit
=
async
(
formValue
:
IProfileForm
)
=>
{
if
(
formValue
.
password
.
length
<
7
)
{
setError
(
'
password length must be greater than 7 characters
'
);
return
;
...
...
@@ -58,7 +60,31 @@ function Profile() {
}
setError
(
''
);
console
.
log
(
'
ready to make update details api call
'
);
try
{
if
(
user
)
{
await
patchUser
(
formValue
,
user
.
id
);
updateUser
({
id
:
user
.
id
,
username
:
formValue
.
name
,
email
:
formValue
.
email
,
type
:
user
.
type
});
toggleEdit
();
}
else
{
setError
(
'
No user id, please relog
'
);
}
}
catch
(
error
)
{
const
errorMessage
=
(
error
as
AxiosError
).
response
?.
data
;
if
(
typeof
errorMessage
==
'
string
'
)
{
setError
(
errorMessage
);
}
else
{
setError
(
'
An unexpected error has occurred
'
);
}
}
};
return
(
...
...
This diff is collapsed.
Click to expand it.
client/src/services/PatchUser/PatchUser.ts
0 → 100644
+
10
−
0
View file @
bbed87bc
import
Api
from
'
../../helpers/Api
'
;
import
{
IProfileForm
}
from
'
../../components/Dashboard/Profile/Profile
'
;
export
function
patchUser
(
form
:
IProfileForm
,
id
:
number
)
{
return
Api
.
patch
(
`User/
${
id
}
`
,
{
Username
:
form
.
name
,
Email
:
form
.
email
,
Password
:
form
.
password
},
{
withCredentials
:
true
});
}
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