-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
22 changed files
with
431 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Loader2 } from "lucide-react"; | ||
|
||
interface ButtonProps { | ||
label: string; | ||
onClick?: () => void; | ||
type: "submit" | "reset" | "button" | undefined; | ||
disabled?: boolean; | ||
loading?: boolean; | ||
} | ||
|
||
const Button = ({ label, onClick, type, disabled, loading }: ButtonProps) => { | ||
return ( | ||
<button | ||
type={type} | ||
onClick={onClick} | ||
disabled={disabled || loading} | ||
className="w-full h-10 p-6 rounded-lg bg-accent transition-all hover:drop-shadow-accent-glow border-2 border-transparent hover:border-white/50 | ||
flex-center font-bold text-lg active:scale-90 disabled:bg-accent/50 disabled:text-foreground/50 disabled:pointer-events-none" | ||
> | ||
{loading ? <Loader2 className="animate-spin duration-200" /> : label} | ||
</button> | ||
); | ||
}; | ||
|
||
export { Button }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { | ||
ForwardRefExoticComponent, | ||
RefAttributes, | ||
useEffect, | ||
useState, | ||
} from "react"; | ||
import { Eye, EyeOff, Info, LucideProps } from "lucide-react"; | ||
|
||
interface InputProps { | ||
name?: string; | ||
label: string; | ||
placeholder: string; | ||
type: React.HTMLInputTypeAttribute | undefined; | ||
autoComplete: React.HTMLInputAutoCompleteAttribute | undefined; | ||
suffixIcon: ForwardRefExoticComponent< | ||
Omit<LucideProps, "ref"> & RefAttributes<SVGSVGElement> | ||
>; | ||
disabled?: boolean; | ||
validation: (value: string) => boolean; | ||
required?: boolean; | ||
} | ||
|
||
const Input = ({ | ||
name, | ||
label, | ||
placeholder, | ||
type, | ||
autoComplete, | ||
suffixIcon: SuffixIcon, | ||
disabled, | ||
validation, | ||
required, | ||
}: InputProps) => { | ||
const [value, setValue] = useState(""); | ||
const [obscure, setObscure] = useState(true); | ||
const [valid, setValid] = useState(false); | ||
|
||
const isPasswod = type === "password"; | ||
const hasInput = value.length > 0; | ||
|
||
useEffect(() => { | ||
setValid(validation(value)); | ||
}, [validation, value]); | ||
|
||
return ( | ||
<div className="space-y-1.5 flex flex-col"> | ||
<div className="flex-between px-1.5"> | ||
<label | ||
className="text-sm font-semibold uppercase" | ||
htmlFor={name?.toLowerCase() ?? label.toLowerCase()} | ||
> | ||
{label} | ||
</label> | ||
<Info size={16} className="text-primary" /> | ||
</div> | ||
<div className="relative flex-center"> | ||
<input | ||
value={value} | ||
onChange={(e) => setValue(e.target.value)} | ||
type={isPasswod ? (obscure ? "password" : "text") : type} | ||
placeholder={placeholder} | ||
autoComplete={autoComplete} | ||
id={name?.toLowerCase() ?? label.toLowerCase()} | ||
name={name?.toLowerCase() ?? label.toLowerCase()} | ||
disabled={disabled} | ||
required={required} | ||
className={`w-full lg:w-[400px] bg-background p-2.5 rounded-lg outline-none border ring-1 focus:ring-2 transition-all placeholder-foreground/50 | ||
px-11 disabled:bg-opacity-25 disabled:border-primary/25 disabled:text-foreground/50 disabled:pointer-events-none | ||
${ | ||
hasInput | ||
? valid | ||
? "border-green-400 focus:border-transparent ring-green-400 focus:ring-green-500" | ||
: "border-red-400 focus:border-transparent ring-red-400 focus:ring-red-500" | ||
: "border-primary/50 focus:border-transparent ring-primary/50 focus:ring-primary" | ||
}`} | ||
/> | ||
<div className="absolute inset-y-0 left-0 flex-center pl-3 pointer-events-none"> | ||
<SuffixIcon size={24} className="text-primary" /> | ||
</div> | ||
{isPasswod && ( | ||
<button | ||
type="button" | ||
onClick={() => setObscure(!obscure)} | ||
className="absolute inset-y-0 right-0 flex-center pr-3" | ||
> | ||
{obscure ? ( | ||
<EyeOff size={24} className="text-primary" /> | ||
) : ( | ||
<Eye size={24} className="text-primary" /> | ||
)} | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export { Input }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Lock, Mail, User } from "lucide-react"; | ||
|
||
import { | ||
ValidateConfirmPassword, | ||
ValidateEmail, | ||
ValidatePassword, | ||
ValidateUsername, | ||
} from "@/lib/utils/validations"; | ||
|
||
export const SIGNUPINPUTS = [ | ||
{ | ||
name: "username", | ||
label: "Username", | ||
placeholder: "e.g. john doe", | ||
type: "text", | ||
autoComplete: "username", | ||
suffixIcon: User, | ||
validation: ValidateUsername, | ||
}, | ||
{ | ||
name: "email", | ||
label: "Email Address", | ||
placeholder: "e.g. [email protected]", | ||
type: "email", | ||
autoComplete: "email", | ||
suffixIcon: Mail, | ||
validation: ValidateEmail, | ||
}, | ||
{ | ||
name: "password", | ||
label: "Password", | ||
placeholder: "e.g. m#P52s@ap$V", | ||
type: "password", | ||
autoComplete: "new-password", | ||
suffixIcon: Lock, | ||
validation: ValidatePassword, | ||
}, | ||
{ | ||
label: "Confirm Password", | ||
placeholder: "e.g. m#P52s@ap$V", | ||
type: "password", | ||
autoComplete: "new-password", | ||
suffixIcon: Lock, | ||
validation: ValidateConfirmPassword, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const SIGNUPKEY = "sign-up"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const EmailRegex = /^[\w.-]+@[a-zA-Z\d.-]+\.[a-zA-Z]{2,}$/; | ||
|
||
const UpperCaseRegex = /[A-Z]/; | ||
const LowerCaseRegex = /[a-z]/; | ||
const NumberRegex = /\d/; | ||
const SpecialRegex = /[!@#$%^&*()_+{}[\]:;<>,.?~\\/-]/; | ||
|
||
export { | ||
EmailRegex, | ||
UpperCaseRegex, | ||
LowerCaseRegex, | ||
NumberRegex, | ||
SpecialRegex, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type SignUpDTO = { | ||
username: string; | ||
email: string; | ||
password: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
|
||
interface QueryProviderProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const QueryProvider = ({ children }: QueryProviderProps) => { | ||
return ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
); | ||
}; | ||
|
||
export default QueryProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Toaster } from "sonner"; | ||
|
||
import { useTheme } from "@/lib/hooks/use-theme"; | ||
|
||
interface ToastProviderProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
const ToastProvider = ({ children }: ToastProviderProps) => { | ||
const { theme } = useTheme(); | ||
|
||
return ( | ||
<> | ||
<Toaster richColors position="top-center" theme={theme} /> | ||
{children} | ||
</> | ||
); | ||
}; | ||
|
||
export default ToastProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { SignUpDTO } from "@/lib/DTO/sign-up.dto"; | ||
import { AppRoutes } from "@/constants/routes"; | ||
|
||
const baseURL = | ||
import.meta.env.VITE_ENV === "development" | ||
? `${import.meta.env.VITE_BASE_URL}/api/auth` | ||
: "/api/auth"; | ||
|
||
export const AuthService = { | ||
signUp: async (signUp: SignUpDTO) => { | ||
return await fetch(`${baseURL}${AppRoutes.SignUp}`, { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify(signUp), | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
EmailRegex, | ||
LowerCaseRegex, | ||
NumberRegex, | ||
SpecialRegex, | ||
UpperCaseRegex, | ||
} from "@/constants/regex"; | ||
|
||
export const ValidateUsername = (username: string) => | ||
username.length > 3 && username.length <= 20; | ||
|
||
export const ValidateEmail = (email: string) => EmailRegex.test(email); | ||
|
||
export const ValidatePassword = (password: string) => { | ||
const criteria = [ | ||
password.length >= 6, | ||
UpperCaseRegex.test(password), | ||
LowerCaseRegex.test(password), | ||
NumberRegex.test(password), | ||
SpecialRegex.test(password), | ||
]; | ||
|
||
return criteria.every((criterion) => criterion); | ||
}; | ||
|
||
export const ValidateConfirmPassword = ({ | ||
pass1, | ||
pass2, | ||
}: { | ||
pass1: string; | ||
pass2: string; | ||
}) => { | ||
if (pass1 !== pass2) return false; | ||
|
||
return true; | ||
}; |
Oops, something went wrong.