Skip to content

Commit

Permalink
WIP: Show login form when clicked on login button
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Apr 10, 2024
1 parent 5e268f7 commit a25bfd6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
15 changes: 12 additions & 3 deletions app/src/client/auth/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useAuth, type CustomizationOptions } from 'wasp/client/auth';
import { createTheme } from '@stitches/react';
import { useAuth } from 'wasp/client/auth';
import { useHistory } from 'react-router-dom';
import { useEffect } from 'react';
import { Link } from 'react-router-dom';
Expand Down Expand Up @@ -26,7 +27,7 @@ export default function Login() {

return (
<AuthWrapper>
<LoginForm logo={imgUrl} />
<LoginForm logo={imgUrl} state={State.Login} />
{/* <br />
<span className='text-sm font-medium text-captn-dark-blue dark:text-captn-dark-blue'>
Don't have an account yet?{' '}
Expand All @@ -47,17 +48,25 @@ export default function Login() {
);
}

export type CustomizationOptions = {
logo?: string;
socialLayout?: 'horizontal' | 'vertical';
appearance?: Parameters<typeof createTheme>[0];
state: State;
};

export function LoginForm({
appearance,
logo,
socialLayout,
state,
}: CustomizationOptions) {
return (
<Auth
appearance={appearance}
logo={logo}
socialLayout={socialLayout}
state={State.Login}
state={state}
/>
);
}
25 changes: 8 additions & 17 deletions app/src/client/auth/LoginSignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useForm } from 'react-hook-form';

import { styled } from './configs/stitches.config';
import { AuthContext } from './Auth';
import { useHistory } from 'react-router-dom';
import config from './configs/config';
import TosAndMarketingEmails from '../components/TosAndMarketingEmails';
import { State } from './Auth';

const SocialAuth = styled('div', {
marginTop: '1.5rem',
Expand Down Expand Up @@ -68,18 +68,9 @@ export const LoginSignupForm = ({
}) => {
const { isLoading, setErrorMessage, setSuccessMessage, setIsLoading } =
useContext(AuthContext);
const isLogin = state === 'login';
const cta = isLogin ? 'Log in' : 'Sign up';
const history = useHistory();
const [tocChecked, setTocChecked] = useState(false);
const [marketingEmailsChecked, setMarketingEmailsChecked] = useState(false);
const [loginFlow, setLoginFlow] = useState('signUp');
// const onErrorHandler = (error) => {
// setErrorMessage({
// title: error.message,
// description: error.data?.data?.message,
// });
// };
const [loginFlow, setLoginFlow] = useState(state);
const hookForm = useForm<LoginSignupFormFields>();
const {
register,
Expand Down Expand Up @@ -118,7 +109,7 @@ export const LoginSignupForm = ({
googleSignInUrl: string
) => {
event.preventDefault();
if (loginFlow === 'signIn') {
if (loginFlow === State.Login) {
updateLocalStorage();
window.location.href = googleSignInUrl;
} else {
Expand All @@ -132,7 +123,7 @@ export const LoginSignupForm = ({
};

const toggleLoginFlow = () => {
const newLoginFlow = loginFlow === 'signIn' ? 'signUp' : 'signIn';
const newLoginFlow = loginFlow === State.Login ? State.Signup : State.Login;
setLoginFlow(newLoginFlow);
setTocChecked(false);
setMarketingEmailsChecked(false);
Expand All @@ -141,11 +132,11 @@ export const LoginSignupForm = ({
};

const googleBtnText =
loginFlow === 'signIn' ? 'Sign in with Google' : 'Sign up with Google';
loginFlow === State.Login ? 'Sign in with Google' : 'Sign up with Google';

return (
<>
{loginFlow === 'signUp' && (
{loginFlow === State.Signup && (
<TosAndMarketingEmails
tocChecked={tocChecked}
handleTocChange={handleTocChange}
Expand Down Expand Up @@ -201,14 +192,14 @@ export const LoginSignupForm = ({
</SocialAuth>
<div className='flex items-center justify-center'>
<span className='text-sm block'>
{loginFlow === 'signIn'
{loginFlow === State.Login
? "Don't have an account? "
: 'Already have an account? '}
<a
className='no-underline hover:underline cursor-pointer'
onClick={toggleLoginFlow}
>
{loginFlow === 'signIn' ? 'Sign Up' : 'Sign In'}
{loginFlow === State.Login ? State.Signup : State.Login}
</a>
</span>
</div>
Expand Down

0 comments on commit a25bfd6

Please sign in to comment.