Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
PPL KI Ganjil 2021 2022
Clicks - Ecosystem Business
clicks-frontend
Commits
762df2c4
Commit
762df2c4
authored
Oct 04, 2021
by
Ahmad Izzudin Alifyandra
Committed by
Bagus Prabowo
Oct 04, 2021
Browse files
Add some redux handling & image upload bugfix
parent
f2776161
Changes
5
Show whitespace changes
Inline
Side-by-side
src/redux/user/actions.tsx
View file @
762df2c4
...
...
@@ -2,6 +2,8 @@ import { Dispatch } from "react-redux/node_modules/@types/react";
import
*
as
userService
from
"
../../service/firestore/user
"
;
import
{
IUser
}
from
"
../../types/firestore/User
"
;
import
*
as
authService
from
"
../../service/firebase/auth
"
;
import
{
ActionErrorRes
}
from
"
../../types/redux
"
;
import
{
AnyAction
}
from
"
redux
"
;
export
const
getUser
=
(
uid
:
string
)
=>
{
return
async
(
dispatch
:
Dispatch
<
any
>
)
=>
{
...
...
@@ -32,7 +34,6 @@ export const setProfilePic = (url: string, id: string) => {
export
const
loginUser
=
(
email
:
string
,
password
:
string
)
=>
{
return
async
(
dispatch
:
Dispatch
<
any
>
)
=>
{
try
{
const
credential
=
authService
.
createCredential
(
email
,
password
);
const
userCredential
=
await
authService
.
loginUser
(
credential
);
...
...
@@ -40,9 +41,6 @@ export const loginUser = (email: string, password: string) => {
const
uid
=
userCredential
.
user
.
uid
;
return
dispatch
(
getUser
(
uid
));
}
catch
(
e
)
{
console
.
log
(
e
);
}
};
};
...
...
@@ -68,6 +66,7 @@ export const changePassword = (oldPassword: string, newPassword: string) => {
return
dispatch
({
type
:
"
CHANGE_PASSWORD
"
});
}
catch
(
e
)
{
console
.
log
(
e
);
return
{
error
:
e
};
}
};
};
...
...
src/redux/user/reducer.tsx
View file @
762df2c4
...
...
@@ -18,8 +18,10 @@ const userReducer = (state = initialState, action: AnyAction): IUser => {
return
action
.
payload
as
IUser
;
case
"
LOGOUT
"
:
return
initialState
;
case
"
SET_PIC
"
:
return
{
...
state
,
pic
:
action
.
payload
}
as
IUser
;
case
"
SET_PIC
"
:
{
const
payload
=
action
.
payload
as
{
pic
:
string
};
return
{
...
state
,
pic
:
payload
.
pic
}
as
IUser
;
}
case
"
CHANGE_PASSWORD
"
:
return
state
;
case
"
SIGNUP
"
:
...
...
src/screens/auth/LoginScreen.tsx
View file @
762df2c4
import
{
useNavigation
}
from
"
@react-navigation/core
"
;
import
*
as
React
from
"
react
"
;
import
{
useState
}
from
"
react
"
;
import
{
StyleSheet
}
from
"
react-native
"
;
import
{
Alert
,
StyleSheet
}
from
"
react-native
"
;
import
MainButton
from
"
../../components/button/MainButton
"
;
import
PlainForm
from
"
../../components/Forms/PlainForm
"
;
import
IconForm
from
"
../../components/Forms/IconForm
"
;
...
...
@@ -11,6 +11,8 @@ import { RootTabScreenProps } from "../../types/navigation";
import
Spacer
from
"
../../components/Spacer/Spacer
"
;
import
{
useAppDispatch
}
from
"
../../hooks/reduxHooks
"
;
import
{
loginUser
}
from
"
../../redux/user/actions
"
;
import
{
IUser
}
from
"
../../types/firestore/User
"
;
import
{
ActionErrorRes
}
from
"
../../types/redux
"
;
const
LoginScreen
=
({
navigation
}:
RootTabScreenProps
<
"
TabOne
"
>
)
=>
{
const
nav
=
useNavigation
();
...
...
@@ -19,7 +21,10 @@ const LoginScreen = ({ navigation }: RootTabScreenProps<"TabOne">) => {
const
dispatch
=
useAppDispatch
();
const
handleSubmit
=
()
=>
{
dispatch
(
loginUser
(
email
,
password
));
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
dispatch
(
loginUser
(
email
,
password
))
.
then
((
e
:
IUser
)
=>
nav
)
.
catch
((
e
:
ActionErrorRes
)
=>
Alert
.
alert
(
"
Invalid credentials
"
));
};
return
(
...
...
src/screens/profile/ChangePasswordScreen.tsx
View file @
762df2c4
...
...
@@ -9,6 +9,7 @@ import Colors from "../../constants/Colors";
import
{
useAppDispatch
}
from
"
../../hooks/reduxHooks
"
;
import
{
RootTabScreenProps
}
from
"
../../types/navigation
"
;
import
{
changePassword
}
from
"
../../redux/user/actions
"
;
import
{
ActionErrorRes
}
from
"
../../types/redux
"
;
const
ChangePasswordScreen
=
({
navigation
,
...
...
@@ -23,8 +24,9 @@ const ChangePasswordScreen = ({
const
handleSubmit
=
()
=>
{
Keyboard
.
dismiss
();
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
dispatch
(
changePassword
(
oldPassword
,
newPassword
)).
then
(()
=>
nav
.
navigate
(
"
SuccessChangePassword
"
)
dispatch
(
changePassword
(
oldPassword
,
newPassword
)).
then
(
(
res
:
ActionErrorRes
)
=>
!
res
.
error
&&
nav
.
navigate
(
"
SuccessChangePassword
"
)
);
};
...
...
src/types/redux.ts
0 → 100644
View file @
762df2c4
export
type
ActionErrorRes
=
{
error
:
any
;
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment