Commit 908f4031 authored by Mithunan Sivakumar's avatar Mithunan Sivakumar
Browse files

Resolve "Implementere bruker registrering"

parent ffef5ee4
......@@ -25,7 +25,7 @@ export default function App() {
const { formState: { errors }, handleSubmit } = methods;
const onSubmit: SubmitHandler<FormValues> = (data: any) => console.log(data);
const onSubmit: SubmitHandler<FormValues> = (values: FormValues) => onFinish(values);
interface FormValues {
email: string;
password: string;
......@@ -36,7 +36,7 @@ const { formState: { errors }, handleSubmit } = methods;
const dispatch = useDispatch();
const { loading, error, loggedIn } = useSelector(({ auth }: ApplicationState) => auth);
// Redirect to homepage if user is already logged in
// TODO Redirect to homepage if user is already logged in
useEffect(() => {
if (loggedIn) {
console.log("push");
......@@ -46,15 +46,13 @@ const { formState: { errors }, handleSubmit } = methods;
// Form completed
const onFinish = (values: FormValues) => {
if (isLogin) {
//const { email, password } = userAdmin;
//dispatch(signIn({ email, password }));
dispatch(signIn({ email: values.email, password: values.password }));
} else {
//const { email, username, password } = userAdmin;
//dispatch(signUp({ email, username: username as string, password }));
dispatch(signUp({ email: values.email, username: values.username || "", password: values.password }));
}
};
// If the redux state contains an error, display an error alert
// TODO If the redux state contains an error, display an error alert
useEffect(() => {
if (error) {
console.log("Show error");
......@@ -97,7 +95,7 @@ const { formState: { errors }, handleSubmit } = methods;
<CustomInput required={true} error={errors.email ? true : false } errorMessage="Du må fylle inn e-post" name="email" placeholder="email" />
<CustomInput required={true} error={errors.password ? true : false } errorMessage="Passorder må oppfylle krav ..." name="password" secureTextEntry={true} placeholder="password" />
<View style={styles.button}>
<Button onPress={handleSubmit(onSubmit)} title={isLogin ? "Login" : "Register"}/>
<Button disabled={loading} onPress={handleSubmit(onSubmit)} title={isLogin ? "Login" : "Register"}/>
<Pressable onPress={() => {setIsLogin(!isLogin); methods.clearErrors()}} style={styles.container}>
<Text style={styles.subText}>
{!isLogin ? "Already have a user? Login." : "Need a new user? Register."}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment