mirror of
https://github.com/urosran/cally.git
synced 2025-08-25 13:49:39 +00:00
additional hooks
This commit is contained in:
30
components/pages/main/Entry.tsx
Normal file
30
components/pages/main/Entry.tsx
Normal file
@ -0,0 +1,30 @@
|
||||
import { View, Text } from "react-native-ui-lib";
|
||||
import React, { useState } from "react";
|
||||
import SignUpPage from "./SignUpPage";
|
||||
import SignInPage from "./SignInPage";
|
||||
import { useSignUp } from "@/hooks/firebase/useSignUp";
|
||||
|
||||
const Entry = () => {
|
||||
const [isRegister, setIsRegister] = useState<boolean>(false);
|
||||
const {mutateAsync: signUp} = useSignUp();
|
||||
|
||||
const setRegister = () => {
|
||||
setIsRegister(true);
|
||||
};
|
||||
const unsetRegister = () => {
|
||||
setIsRegister(false);
|
||||
};
|
||||
return (
|
||||
<View>
|
||||
{isRegister ? (
|
||||
<SignUpPage
|
||||
unsetRegister={unsetRegister}
|
||||
/>
|
||||
) : (
|
||||
<SignInPage setRegister={setRegister} />
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default Entry;
|
41
components/pages/main/SignInPage.tsx
Normal file
41
components/pages/main/SignInPage.tsx
Normal file
@ -0,0 +1,41 @@
|
||||
import { View, Text, Button } from "react-native-ui-lib";
|
||||
import { TextInput } from "react-native";
|
||||
import React, { useState } from "react";
|
||||
import { useSignIn } from "@/hooks/firebase/useSignIn";
|
||||
|
||||
const SignInPage = (props: {
|
||||
setRegister: () => any;
|
||||
}) => {
|
||||
const [email, setEmail] = useState<string>("");
|
||||
const [password, setPassword] = useState<string>("");
|
||||
|
||||
const { mutateAsync: signIn } = useSignIn();
|
||||
|
||||
const handleSignIn = async () => {
|
||||
await signIn({email, password});
|
||||
}
|
||||
|
||||
return (
|
||||
<View marginH-20>
|
||||
<TextInput placeholder="Email" value={email} onChangeText={setEmail} />
|
||||
<TextInput
|
||||
placeholder="Password"
|
||||
value={password}
|
||||
onChangeText={setPassword}
|
||||
secureTextEntry
|
||||
/>
|
||||
<Button label="Login" onPress={handleSignIn} />
|
||||
<Text>Don't have an account?</Text>
|
||||
<Button
|
||||
onPress={props.setRegister}
|
||||
label="Sign Up"
|
||||
link
|
||||
padding-0
|
||||
margin-0
|
||||
left
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default SignInPage;
|
83
components/pages/main/SignUpPage.tsx
Normal file
83
components/pages/main/SignUpPage.tsx
Normal file
@ -0,0 +1,83 @@
|
||||
import { TextInput } from "react-native";
|
||||
import React, { useState } from "react";
|
||||
import { Checkbox, Button, View, Text } from "react-native-ui-lib";
|
||||
import { useSignUp } from "@/hooks/firebase/useSignUp";
|
||||
import { ProfileType } from "@/contexts/AuthContext";
|
||||
|
||||
const SignUpPage = (props: { unsetRegister: () => any }) => {
|
||||
const [email, setEmail] = useState<string>("");
|
||||
const [password, setPassword] = useState<string>("");
|
||||
const [isParent, setIsParent] = useState<boolean>(true);
|
||||
const [isChild, setIsChild] = useState<boolean>(false);
|
||||
const [isCaregiver, setIsCaregiver] = useState<boolean>(false);
|
||||
const [profileType, setProfileType] = useState<ProfileType>(
|
||||
ProfileType.PARENT
|
||||
);
|
||||
const { mutateAsync: signUp } = useSignUp();
|
||||
|
||||
const handleSignUp = async () => {
|
||||
await signUp({ email, password });
|
||||
};
|
||||
|
||||
return (
|
||||
<View marginH-20>
|
||||
<TextInput placeholder="Email" value={email} onChangeText={setEmail} />
|
||||
<TextInput
|
||||
placeholder="Password"
|
||||
value={password}
|
||||
onChangeText={setPassword}
|
||||
secureTextEntry
|
||||
/>
|
||||
<Button label="Register" onPress={handleSignUp} />
|
||||
<Text>Choose Profile Type:</Text>
|
||||
<Checkbox
|
||||
label="Parent"
|
||||
value={isParent}
|
||||
onValueChange={(value) => {
|
||||
setIsParent(value);
|
||||
setProfileType(ProfileType.PARENT);
|
||||
if (value) {
|
||||
setIsChild(false);
|
||||
setIsCaregiver(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Checkbox
|
||||
label="Child"
|
||||
value={isChild}
|
||||
onValueChange={(value) => {
|
||||
setIsChild(value);
|
||||
setProfileType(ProfileType.CHILD);
|
||||
if (value) {
|
||||
setIsParent(false);
|
||||
setIsCaregiver(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Checkbox
|
||||
label="Caregiver"
|
||||
value={isCaregiver}
|
||||
onValueChange={(value) => {
|
||||
setIsCaregiver(value);
|
||||
setProfileType(ProfileType.CAREGIVER);
|
||||
if (value) {
|
||||
setIsParent(false);
|
||||
setIsChild(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Text>
|
||||
Already have an account?
|
||||
<Button
|
||||
label="Sign In"
|
||||
margin-0
|
||||
link
|
||||
text200
|
||||
onPress={props.unsetRegister}
|
||||
/>
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default SignUpPage;
|
Reference in New Issue
Block a user