-
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.
feat(admin): ✨ added create new store page
- Loading branch information
Showing
62 changed files
with
5,074 additions
and
918 deletions.
There are no files selected for viewing
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,2 @@ | ||
NEXT_PUBLIC_API_URL= | ||
NEXT_PUBLIC_GOOGLE_CLIENT_ID= |
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,29 @@ | ||
import { Stack, Button, Box } from "@chakra-ui/react"; | ||
import { FcGoogle } from "react-icons/fc"; | ||
import { GOOGLE_OAUTH_REDIRECT_URL } from "../../../constants"; | ||
|
||
const SignInWithGoogle = () => ( | ||
<Stack spacing="4" as="a" href={getGoogleOAuthUrl()}> | ||
<Button leftIcon={<Box as={FcGoogle} />}>Continue with Google</Button> | ||
</Stack> | ||
); | ||
|
||
export default SignInWithGoogle; | ||
|
||
export const getGoogleOAuthUrl = () => { | ||
const rootUrl = "https://accounts.google.com/o/oauth2/v2/auth"; | ||
|
||
const qs = new URLSearchParams({ | ||
redirect_uri: GOOGLE_OAUTH_REDIRECT_URL, | ||
client_id: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID, | ||
access_type: "offline", | ||
response_type: "code", | ||
prompt: "consent", | ||
scope: [ | ||
"https://www.googleapis.com/auth/userinfo.profile", | ||
"https://www.googleapis.com/auth/userinfo.email", | ||
].join(" "), | ||
}); | ||
|
||
return `${rootUrl}?${qs.toString()}`; | ||
}; |
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,158 @@ | ||
import { | ||
Button, | ||
Flex, | ||
LightMode, | ||
Stack, | ||
Text, | ||
useColorModeValue as mode, | ||
useToast, | ||
} from "@chakra-ui/react"; | ||
import { useForm } from "react-hook-form"; | ||
import { yupResolver } from "@hookform/resolvers/yup"; | ||
import * as Yup from "yup"; | ||
import { useRouter } from "next/router"; | ||
import { useAdminLoginMutation } from "@/generated/graphql"; | ||
import UnderlineLink from "@/components/ui/UnderlineLink"; | ||
import InputField from "../ui/InputField"; | ||
|
||
interface FormValues { | ||
email: string; | ||
password: string; | ||
} | ||
|
||
const LoginFormSchema = Yup.object({ | ||
email: Yup.string().email().required("Required"), | ||
password: Yup.string() | ||
.required("Required") | ||
.min(8, "Too Short") | ||
.max(20, "Too Long"), | ||
}); | ||
|
||
const LoginForm = () => { | ||
const toast = useToast(); | ||
const router = useRouter(); | ||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, dirtyFields }, | ||
setError, | ||
} = useForm<FormValues>({ | ||
defaultValues: { | ||
email: "", | ||
password: "", | ||
}, | ||
resolver: yupResolver(LoginFormSchema), | ||
}); | ||
const [loginMutation, { loading }] = useAdminLoginMutation({ | ||
onCompleted: (data) => { | ||
const { errors: userErrors, user } = data.adminLogin; | ||
if (userErrors) { | ||
toast({ | ||
title: "Login Failed", | ||
description: userErrors[0].message, | ||
status: "error", | ||
duration: 5000, | ||
isClosable: true, | ||
}); | ||
setError(userErrors[0].field as "email" | "password", { | ||
type: "manual", | ||
message: userErrors[0].message, | ||
}); | ||
} else { | ||
toast({ | ||
title: "Login successful", | ||
description: `Welcome back, ${user?.first_name}!`, | ||
status: "success", | ||
duration: 5000, | ||
isClosable: true, | ||
}); | ||
router.push((router.query.redirect as string) ?? "/dashboard"); | ||
} | ||
}, | ||
onError: (error) => { | ||
toast({ | ||
title: "Login Failed", | ||
description: error.message, | ||
status: "error", | ||
duration: 5000, | ||
isClosable: true, | ||
}); | ||
}, | ||
refetchQueries: ["MeStaff"], | ||
}); | ||
|
||
return ( | ||
<form | ||
onSubmit={handleSubmit((values) => | ||
loginMutation({ | ||
variables: { | ||
email: values.email, | ||
password: values.password, | ||
}, | ||
}) | ||
)} | ||
> | ||
<Stack spacing="-px"> | ||
<InputField | ||
register={{ ...register("email") }} | ||
error={errors.email} | ||
touched={dirtyFields.email} | ||
showErrorMessage={false} | ||
showLabel={false} | ||
required | ||
name="email" | ||
type="email" | ||
label="Email address" | ||
autoComplete="email" | ||
placeholder="Email address" | ||
size="lg" | ||
bg={mode("white", "gray.700")} | ||
fontSize="md" | ||
roundedBottom="0" | ||
/> | ||
<InputField | ||
register={{ ...register("password") }} | ||
error={errors.password} | ||
touched={dirtyFields.password} | ||
showErrorMessage={false} | ||
showLabel={false} | ||
label="Password" | ||
name="password" | ||
type="password" | ||
autoComplete="current-password" | ||
required | ||
size="lg" | ||
bg={mode("white", "gray.700")} | ||
fontSize="md" | ||
roundedTop="0" | ||
placeholder="Password" | ||
/> | ||
</Stack> | ||
<Flex align="center" justify="space-between" mt="8"> | ||
<Text> | ||
Dont Have a Store yet?{" "} | ||
<UnderlineLink href="/auth/register">Create Store</UnderlineLink> | ||
</Text> | ||
<UnderlineLink href="/auth/forgot-password" fontSize="sm"> | ||
Forgot Password | ||
</UnderlineLink> | ||
</Flex> | ||
<LightMode> | ||
<Button | ||
isLoading={loading} | ||
size="lg" | ||
type="submit" | ||
mt="8" | ||
w="full" | ||
colorScheme="primary" | ||
fontSize="md" | ||
fontWeight="bold" | ||
> | ||
Sign in | ||
</Button> | ||
</LightMode> | ||
</form> | ||
); | ||
}; | ||
|
||
export default LoginForm; |
Oops, something went wrong.
b241dce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ecommerce-admin-client – ./apps/admin
ecommerce-admin-client-git-main-sahrohit.vercel.app
ecommerce-admin-client-sahrohit.vercel.app
adminpasal.vercel.app
b241dce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ecommerce-storefront-client – ./apps/storefront
ecommerce-storefront-client-git-main-sahrohit.vercel.app
ecommerce-storefront-client-sahrohit.vercel.app
hamropasal.vercel.app
www.rudejellyfish.live
rudejellyfish.live