Skip to content

Commit

Permalink
refactor: Rename auth/SignIn components to common/VerticalForm
Browse files Browse the repository at this point in the history
because they're used for more than just signing in
  • Loading branch information
SheepTester committed Apr 23, 2024
1 parent 0ad068a commit e75f2c0
Show file tree
Hide file tree
Showing 23 changed files with 105 additions and 79 deletions.
3 changes: 0 additions & 3 deletions src/components/auth/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ interface DisplayOptions {
style?: CSSProperties;
}

type SignInButtonProps = (LinkInterface | ButtonInterface) & DisplayOptions;
type VerticalFormButtonProps = (LinkInterface | ButtonInterface) & DisplayOptions;

const SignInButton = (props: SignInButtonProps) => {
const VerticalFormButton = (props: VerticalFormButtonProps) => {
const { type, text, display, style = {} } = props;

if (type === 'link') {
Expand All @@ -45,4 +45,4 @@ const SignInButton = (props: SignInButtonProps) => {
return null;
};

export default SignInButton;
export default VerticalFormButton;
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ interface FormItemProps {
inputHeight?: string;
}

type SignInFormProps = FormItemProps & (InputTypeProps | SelectTypeProps);
type VerticalFormProps = FormItemProps & (InputTypeProps | SelectTypeProps);

const SignInFormItem = (props: SignInFormProps) => {
const VerticalFormItem = (props: VerticalFormProps) => {
const { icon, placeholder, formRegister, element, error, inputHeight } = props;

if (element === 'input') {
Expand Down Expand Up @@ -74,4 +74,4 @@ const SignInFormItem = (props: SignInFormProps) => {
return null;
};

export default SignInFormItem;
export default VerticalFormItem;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import styles from './style.module.scss';

interface SignInTitleProps {
interface VerticalFormTitleProps {
text: string;
description?: string;
}

const SignInTitle = ({ text, description }: SignInTitleProps) => {
const VerticalFormTitle = ({ text, description }: VerticalFormTitleProps) => {
return (
<>
<h1 className={styles.title}>{text}</h1>
Expand All @@ -14,4 +14,4 @@ const SignInTitle = ({ text, description }: SignInTitleProps) => {
);
};

export default SignInTitle;
export default VerticalFormTitle;
3 changes: 3 additions & 0 deletions src/components/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ export { default as SEO } from './SEO';
export { default as Typography } from './Typography';
export type { Variant } from './Typography';
export { default as VerticalForm } from './VerticalForm';
export { default as VerticalFormButton } from './VerticalFormButton';
export { default as VerticalFormItem } from './VerticalFormItem';
export { default as VerticalFormTitle } from './VerticalFormTitle';
5 changes: 2 additions & 3 deletions src/components/profile/UserHandleNotFound/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SignInButton } from '@/components/auth';
import { Typography, VerticalForm } from '@/components/common';
import { Typography, VerticalForm, VerticalFormButton } from '@/components/common';
import Cat404 from '@/public/assets/graphics/cat404.png';
import Image from 'next/image';

Expand All @@ -13,6 +12,6 @@ export const UserHandleNotFound = ({ handle }: UserHandleNotFoundProps) => (
No user with handle &lsquo;{handle}&rsquo; was found.
</Typography>
<Image src={Cat404} width={256} height={256} alt="Sad Cat" />
<SignInButton type="link" display="button1" href="/" text="Return to Home" />
<VerticalFormButton type="link" display="button1" href="/" text="Return to Home" />
</VerticalForm>
);
5 changes: 2 additions & 3 deletions src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SignInButton } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import { VerticalForm, VerticalFormButton } from '@/components/common';
import Cat404 from '@/public/assets/graphics/cat404.png';
import styles from '@/styles/pages/404.module.scss';
import Image from 'next/image';
Expand All @@ -10,7 +9,7 @@ const PageNotFound = () => {
<VerticalForm style={{ alignItems: 'center', flex: 'auto', height: 'unset' }}>
<h1 className={styles.header}>Whoops, we ended up on the wrong page!</h1>
<Image src={Cat404} width={256} height={256} alt="Sad Cat" />
<SignInButton type="link" display="button1" href="/" text="Return to Home" />
<VerticalFormButton type="link" display="button1" href="/" text="Return to Home" />
</VerticalForm>
</div>
);
Expand Down
5 changes: 2 additions & 3 deletions src/pages/500.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SignInButton } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import { VerticalForm, VerticalFormButton } from '@/components/common';
import Cat404 from '@/public/assets/graphics/cat404.png';
import styles from '@/styles/pages/404.module.scss';
import Image from 'next/image';
Expand All @@ -17,7 +16,7 @@ const InternalServerError = () => {
>
Logging out will usually fix your issue.
</span>
<SignInButton type="link" display="button1" href="/logout" text="Logout" />
<VerticalFormButton type="link" display="button1" href="/logout" text="Logout" />
<span
style={{
textAlign: 'center',
Expand Down
18 changes: 11 additions & 7 deletions src/pages/admin/attendance.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { SignInButton, SignInFormItem, SignInTitle } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import {
VerticalForm,
VerticalFormButton,
VerticalFormItem,
VerticalFormTitle,
} from '@/components/common';
import { config } from '@/lib';
import withAccessType from '@/lib/hoc/withAccessType';
import { PermissionService, ValidationService } from '@/lib/services';
Expand All @@ -26,11 +30,11 @@ const AwardPointsPage: NextPage = () => {

return (
<VerticalForm onEnterPress={handleSubmit(onSubmit)}>
<SignInTitle
<VerticalFormTitle
text="Retroactive Attendance"
description="Mark members as attended for past events"
/>
<SignInFormItem
<VerticalFormItem
icon={<AiOutlineMail />}
element="input"
name="email"
Expand All @@ -44,7 +48,7 @@ const AwardPointsPage: NextPage = () => {
})}
error={errors.email}
/>
<SignInFormItem
<VerticalFormItem
icon={<AiOutlineMail />}
element="input"
name="description"
Expand All @@ -55,7 +59,7 @@ const AwardPointsPage: NextPage = () => {
})}
error={errors.description}
/>
<SignInFormItem
<VerticalFormItem
icon={<VscLock />}
name="points"
element="input"
Expand All @@ -66,7 +70,7 @@ const AwardPointsPage: NextPage = () => {
})}
error={errors.points}
/>
<SignInButton
<VerticalFormButton
type="button"
display="button1"
text="Award Points"
Expand Down
16 changes: 10 additions & 6 deletions src/pages/admin/milestone.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { SignInButton, SignInFormItem, SignInTitle } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import {
VerticalForm,
VerticalFormButton,
VerticalFormItem,
VerticalFormTitle,
} from '@/components/common';
import { config } from '@/lib';
import withAccessType from '@/lib/hoc/withAccessType';
import { PermissionService } from '@/lib/services';
Expand All @@ -25,11 +29,11 @@ const AwardPointsPage: NextPage = () => {

return (
<VerticalForm onEnterPress={handleSubmit(onSubmit)}>
<SignInTitle
<VerticalFormTitle
text="Create Milestone"
description="Award points to all active users (e.g. for ACM's 8 year anniversary)"
/>
<SignInFormItem
<VerticalFormItem
icon={<AiOutlineMail />}
element="input"
name="name"
Expand All @@ -40,7 +44,7 @@ const AwardPointsPage: NextPage = () => {
})}
error={errors.name}
/>
<SignInFormItem
<VerticalFormItem
icon={<VscLock />}
name="points"
element="input"
Expand All @@ -51,7 +55,7 @@ const AwardPointsPage: NextPage = () => {
})}
error={errors.points}
/>
<SignInButton
<VerticalFormButton
type="button"
display="button1"
text="Create Milestone"
Expand Down
21 changes: 14 additions & 7 deletions src/pages/admin/points.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { SignInButton, SignInFormItem, SignInTitle } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import {
VerticalForm,
VerticalFormButton,
VerticalFormItem,
VerticalFormTitle,
} from '@/components/common';
import { config } from '@/lib';
import withAccessType from '@/lib/hoc/withAccessType';
import { PermissionService, ValidationService } from '@/lib/services';
Expand All @@ -26,8 +30,11 @@ const AwardPointsPage: NextPage = () => {

return (
<VerticalForm onEnterPress={handleSubmit(onSubmit)}>
<SignInTitle text="Award Bonus Points" description="Grant Bonus Points to a Specific User" />
<SignInFormItem
<VerticalFormTitle
text="Award Bonus Points"
description="Grant Bonus Points to a Specific User"
/>
<VerticalFormItem
icon={<AiOutlineMail />}
element="input"
name="email"
Expand All @@ -41,7 +48,7 @@ const AwardPointsPage: NextPage = () => {
})}
error={errors.email}
/>
<SignInFormItem
<VerticalFormItem
icon={<AiOutlineMail />}
element="input"
name="description"
Expand All @@ -52,7 +59,7 @@ const AwardPointsPage: NextPage = () => {
})}
error={errors.description}
/>
<SignInFormItem
<VerticalFormItem
icon={<VscLock />}
name="points"
element="input"
Expand All @@ -63,7 +70,7 @@ const AwardPointsPage: NextPage = () => {
})}
error={errors.points}
/>
<SignInButton
<VerticalFormButton
type="button"
display="button1"
text="Award Points"
Expand Down
5 changes: 2 additions & 3 deletions src/pages/check-email.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SignInButton } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import { VerticalForm, VerticalFormButton } from '@/components/common';
import styles from '@/styles/pages/check-email.module.scss';
import type { GetServerSideProps } from 'next';

Expand All @@ -21,7 +20,7 @@ const CheckEmail = ({ email }: CheckEmailProps) => {
We&apos;ve sent an email to <b>{email}</b> to verify your email address and activate your
account.
</span>
<SignInButton
<VerticalFormButton
type="link"
display="button1"
href="/login"
Expand Down
14 changes: 9 additions & 5 deletions src/pages/forgot-password.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { SignInButton, SignInFormItem, SignInTitle } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import {
VerticalForm,
VerticalFormButton,
VerticalFormItem,
VerticalFormTitle,
} from '@/components/common';
import { config, showToast } from '@/lib';
import { AuthManager } from '@/lib/managers';
import { ValidationService } from '@/lib/services';
Expand Down Expand Up @@ -34,8 +38,8 @@ const ForgotPassword: NextPage = () => {

return (
<VerticalForm onEnterPress={handleSubmit(onSubmit)}>
<SignInTitle text="Forgot Password" />
<SignInFormItem
<VerticalFormTitle text="Forgot Password" />
<VerticalFormItem
icon={<AiOutlineMail />}
element="input"
name="email"
Expand All @@ -49,7 +53,7 @@ const ForgotPassword: NextPage = () => {
})}
error={errors.email}
/>
<SignInButton
<VerticalFormButton
type="button"
display="button1"
text="Submit"
Expand Down
20 changes: 12 additions & 8 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { SignInButton, SignInFormItem, SignInTitle } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import {
VerticalForm,
VerticalFormButton,
VerticalFormItem,
VerticalFormTitle,
} from '@/components/common';
import { config, showToast } from '@/lib';
import { resendEmailVerification } from '@/lib/api/AuthAPI';
import { AuthManager } from '@/lib/managers';
Expand Down Expand Up @@ -65,8 +69,8 @@ const LoginPage: NextPage<LoginProps> = ({ destination }) => {

return (
<VerticalForm onEnterPress={handleSubmit(onSubmit)}>
<SignInTitle text="Welcome to ACM!" />
<SignInFormItem
<VerticalFormTitle text="Welcome to ACM!" />
<VerticalFormItem
icon={<AiOutlineMail />}
element="input"
name="email"
Expand All @@ -80,7 +84,7 @@ const LoginPage: NextPage<LoginProps> = ({ destination }) => {
})}
error={errors.email}
/>
<SignInFormItem
<VerticalFormItem
icon={<VscLock />}
name="password"
element="input"
Expand All @@ -91,19 +95,19 @@ const LoginPage: NextPage<LoginProps> = ({ destination }) => {
})}
error={errors.password}
/>
<SignInButton
<VerticalFormButton
type="link"
display="link"
text="Forgot your password?"
href="/forgot-password"
/>
<SignInButton
<VerticalFormButton
type="button"
display="button1"
text="Sign In"
onClick={handleSubmit(onSubmit)}
/>
<SignInButton type="link" href="/register" text="Sign Up" display="button2" />
<VerticalFormButton type="link" href="/register" text="Sign Up" display="button2" />
</VerticalForm>
);
};
Expand Down
Loading

0 comments on commit e75f2c0

Please sign in to comment.