Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api connection #26

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 37 additions & 36 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
.env
79 changes: 79 additions & 0 deletions app/chef/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import Image from 'next/image'
import Link from 'next/link'

export default function Footer() {
const footer_elements = [
'About',
'Terms & conditions',
'Privacy Policy',
'Contact',
]
return (
<div className="relative bg-white">
<div className="flex justify-between w-full p-8 px-28">
<div>
<Link href="/chef/video">
<Image
src="/svg/WecookedLogo.svg"
alt="WeCooked Logo"
width={120}
height={120}
className="cursor-pointer"
/>
</Link>
</div>
<div className="flex gap-x-6">
{footer_elements.map((item, index) => (
<ul
key={index}
className="cursor-pointer hover:text-transparent bg-clip-text bg-gradient-to-t from-[#FE3511] to-[#F0725C]"
>
{item}
</ul>
))}
Comment on lines +26 to +33
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace ul with li elements for proper semantic HTML

The mapping of footer elements should use li elements within a parent ul, not individual ul elements for each item.

-<div className="flex gap-x-6">
-  {footer_elements.map((item, index) => (
-    <ul
-      key={index}
-      className="cursor-pointer hover:text-transparent bg-clip-text bg-gradient-to-t from-[#FE3511] to-[#F0725C]"
-    >
-      {item}
-    </ul>
-  ))}
-</div>
+<ul className="flex gap-x-6">
+  {footer_elements.map((item, index) => (
+    <li
+      key={index}
+      className="cursor-pointer hover:text-transparent bg-clip-text bg-gradient-to-t from-[#FE3511] to-[#F0725C]"
+    >
+      {item}
+    </li>
+  ))}
+</ul>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{footer_elements.map((item, index) => (
<ul
key={index}
className="cursor-pointer hover:text-transparent bg-clip-text bg-gradient-to-t from-[#FE3511] to-[#F0725C]"
>
{item}
</ul>
))}
<ul className="flex gap-x-6">
{footer_elements.map((item, index) => (
<li
key={index}
className="cursor-pointer hover:text-transparent bg-clip-text bg-gradient-to-t from-[#FE3511] to-[#F0725C]"
>
{item}
</li>
))}
</ul>

</div>
<div className="flex items-center gap-x-3">
<Link href="/">
<Image
src="/svg/fb-ic.svg"
alt="Facebook icon"
width={25}
height={25}
className="cursor-pointer"
/>
</Link>
<Link href="/">
<Image
src="/svg/tweet-ic.svg"
alt="twitter icon"
width={25}
height={25}
className="cursor-pointer"
/>
</Link>
<Link href="/">
<Image
src="/svg/insta-ic.svg"
alt="instagram icon"
width={25}
height={25}
className="cursor-pointer"
/>
</Link>
<Link href="/">
<Image
src="/svg/google-ic.svg"
alt="Google icon"
width={25}
height={25}
className="cursor-pointer"
/>
</Link>
Comment on lines +36 to +71
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add proper social media links and aria-labels

The social media links currently point to "/" which is not ideal for production. Also, add aria-labels for better accessibility.

-<Link href="/">
+<Link 
+  href="https://facebook.com/wecooked" 
+  target="_blank" 
+  rel="noopener noreferrer"
+  aria-label="Visit WeCooked Facebook page">
   <Image
     src="/svg/fb-ic.svg"
     alt="Facebook icon"
     width={25}
     height={25}
     className="cursor-pointer"
   />
 </Link>

(Apply similar changes to other social media links)

Committable suggestion skipped: line range outside the PR's diff.

</div>
</div>
<div className="flex justify-center pb-16">
Copyright ©{new Date().getFullYear()} Wecooked
</div>
</div>
)
}
3 changes: 1 addition & 2 deletions app/chef/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import NavLink from './NavLink'
import { useRouter } from 'next/navigation'
import { useAuthContext } from '@/app/contexts/authcontext'


/**
* Custom hook to manage authentication state in localStorage.
* Wrapped in useEffect to prevent SSR issues with Netlify.
Expand Down Expand Up @@ -90,7 +89,7 @@ export default function Navbar() {
aria-orientation="vertical"
>
<Link
href="/client/profile"
href="/chef/profile"
className="block px-4 py-2 hover:bg-gray-100"
role="menuitem"
>
Expand Down
40 changes: 40 additions & 0 deletions app/chef/components/course/CourseUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,46 @@ export default function CourseUpload() {
setIsSubmitting(true)
setSubmitError(null)

const courseUploadData = [
{
courseTitle: 'Masterbate British Cuisine',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Typographical error in courseTitle

There's a typo in courseTitle: 'Masterbate British Cuisine'. Did you mean 'Master British Cuisine'?

courseDetail:
'Learn the secrets of British cuisine from Gordon Ramsay.',
coursePrice: 100,
courseCategory: 'Cooking',
courseVideoId: 1,
courseChefId: 1,
coursePackId: 'pack1',
courseVideoPath: 'test12345678.com',
courseIngredientPrice: 123456,
courseIngredientDetail: 'Pork,Pork,Pork,Pork',
courseImage: 'placeholderImage.com',
},
]
Comment on lines +100 to +115
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace hardcoded courseUploadData with form data

Currently, courseUploadData is hardcoded and does not use the data entered by the user in the form. This means that the user's input is not being sent to the backend, and instead, placeholder data is submitted.

Apply this diff to construct courseUploadData using form state variables:

 const courseUploadData = [
   {
-    courseTitle: 'Masterbate British Cuisine',
+    courseTitle: courseName,
-    courseDetail: 'Learn the secrets of British cuisine from Gordon Ramsay.',
+    courseDetail: courseDetail,
-    coursePrice: 100,
+    coursePrice: coursePrice,
-    courseCategory: 'Cooking',
+    courseCategory: courseCategory,
-    courseVideoId: 1,
+    courseVideoId: /* assign appropriate video ID */,
-    courseChefId: 1,
+    courseChefId: /* assign appropriate chef ID */,
-    coursePackId: 'pack1',
+    coursePackId: /* assign appropriate pack ID */,
-    courseVideoPath: 'test12345678.com',
+    courseVideoPath: videoUrl,
-    courseIngredientPrice: 123456,
+    courseIngredientPrice: /* calculate ingredient price if applicable */,
-    courseIngredientDetail: 'Pork,Pork,Pork,Pork',
+    courseIngredientDetail: courseIngredients,
-    courseImage: 'placeholderImage.com',
+    courseImage: coverImageUrl,
   },
 ]

Please replace the placeholders with the appropriate variables or calculations.

Committable suggestion skipped: line range outside the PR's diff.

try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/chef/upload`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(courseUploadData),
}
)

if (response.ok) {
const responseData = await response.json()
console.log('Upload successful:', responseData)
} else {
const errorDetails = await response.json() // Optional: read error response
console.error('Failed to upload:', response.status, errorDetails)
}
} catch (error) {
console.error('Error submitting the form:', error)
}


try {
const courseData: CourseSubmission = {
courseName,
Expand Down
45 changes: 38 additions & 7 deletions app/chef/components/login&forget-password/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AuthContext, useAuthContext } from '@/app/contexts/authcontext'
import { useForm } from 'react-hook-form'
import { z } from 'zod'
import { zodResolver } from '@hookform/resolvers/zod'
import Cookies from 'js-cookie'

// Define the validation schema
const loginSchema = z.object({
Expand Down Expand Up @@ -56,19 +57,49 @@ export default function Login() {
const login = () => {
setIsAuthenticated(true)
router.push('/chef/course')
if (remember == true && typeof window !== 'undefined') {
// Access localStorage here (to prevent netlify approvement fail)
localStorage.setItem('isAuthenticated', 'true')
if (remember) {
// Store authentication state in cookies
Cookies.set('Authorization', 'true', { expires: 7 }) // expires in 7 days if "Remember me" is checked
} else {

Comment on lines +60 to +64
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Enhance cookie security settings

The cookie settings need security improvements:

  1. Add httpOnly flag
  2. Add secure flag for HTTPS
  3. Add sameSite attribute

Update cookie settings:

-Cookies.set('Authorization', 'true', { expires: 7 })
+Cookies.set('Authorization', 'true', {
+  expires: 7,
+  secure: true,
+  sameSite: 'strict',
+  httpOnly: true
+})

Committable suggestion skipped: line range outside the PR's diff.

}
}

const togglePasswordVisibility = () => setShowPassword((prev) => !prev)
const toggleRemember = () => setRemember((prev) => !prev)

// Update handleFormSubmit to handle form data
const handleFormSubmit = (data: LoginFormData) => {
console.log(JSON.stringify(data)) // Placeholder for auth logic
login() //set login state to true
const handleFormSubmit = async (data: LoginFormData) => {

const chefLoginData = [{
chefEmail: data.email,
chefPassword: data.password,
}]

try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/chef/login`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(chefLoginData),
}
)

if (!response.ok) {
throw new Error('Login failed')
}

const responseData = await response.json()
console.log('token received:', responseData.token)
Cookies.set('Authorization', responseData.token)

login() // Redirect to the home page
} catch (error) {
console.error('Login failed:', error)
}
Comment on lines +72 to +102
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve error handling and user feedback

The login error handling needs improvement:

  1. Add specific error messages for different failure scenarios
  2. Provide user feedback during login attempt
  3. Handle network errors gracefully

Example implementation:

 try {
+  setIsLoading(true)
   const response = await fetch(...)
   if (!response.ok) {
-    throw new Error('Login failed')
+    const errorData = await response.json()
+    throw new Error(errorData.message || 'Login failed')
   }
   // ... rest of the code
 } catch (error) {
-  console.error('Login failed:', error)
+  setError(error.message)
+  // Show error message to user
 } finally {
+  setIsLoading(false)
 }

Committable suggestion skipped: line range outside the PR's diff.

}

return (
Expand Down Expand Up @@ -184,7 +215,7 @@ export default function Login() {
<div className="flex justify-center mt-6 gap-x-1 text-sm">
<p>Don&apos;t have an account?</p>
<Link
href="/client/sign-up"
href="/chef/sign-up-chef"
className="cursor-pointer text-transparent bg-clip-text bg-gradient-to-t from-[#FE3511] to-[#F0725C] hover:underline font-medium"
>
Sign up now
Expand Down
Loading