Skip to content

Commit b5e176d

Browse files
committed
Merge branch 'dev' of https://github.com/LTU-D0020E/d0020e-project-dpp into profilePageV3
2 parents 84e2e31 + f791de4 commit b5e176d

24 files changed

+885
-306
lines changed

package-lock.json

+105-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@headlessui/react": "^1.7.17",
1313
"@heroicons/react": "^2.0.18",
1414
"@yudiel/react-qr-scanner": "^1.2.6",
15-
"axios": "^1.6.2",
15+
"axios": "^1.6.7",
1616
"bcrypt": "^5.1.1",
1717
"bcryptjs": "^2.4.3",
1818
"clsx": "^2.0.0",
@@ -25,6 +25,7 @@
2525
"next-auth": "^4.24.5",
2626
"next-progress": "^2.3.1",
2727
"react": "^18",
28+
"react-datepicker": "^6.2.0",
2829
"react-device-detect": "^2.2.3",
2930
"react-dom": "^18",
3031
"react-modal": "^3.16.1",

public/683424-200.png

5.82 KB
Loading

public/lifecycle.png

7.02 KB
Loading

public/volvo.svg

+2
Loading

src/components/Global/NavbarGlobal.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function NavbarGlobal({ searchBar = true, navClassName }) {
2525

2626
{/* Conditionally render SearchBar */}
2727
{searchBar && (
28-
<div className='mx-auto w-max'>
28+
<div className='z-30 mx-auto w-[500px]'>
2929
<SearchBar />
3030
</div>
3131
)}

src/components/Global/SearchBar.jsx

+16-21
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ export default function SearchBar({ className, ...props }) {
1414
const [showSearchResults, setShowSearchResults] = useState(false)
1515

1616
const handleSearch = async () => {
17+
if (searchTerm.trim() === '') {
18+
setSearchResult([])
19+
return
20+
}
21+
1722
setLoading(true)
1823

1924
try {
2025
const response = await fetch(`/api/v1/search?query=${searchTerm}`)
2126
const data = await response.json()
22-
setSearchResult(data)
27+
setSearchResult(data.successful)
2328
} catch (error) {
2429
console.error('Error fetching search results:', error)
2530
setSearchResult([])
@@ -29,35 +34,25 @@ export default function SearchBar({ className, ...props }) {
2934
}
3035

3136
useEffect(() => {
32-
if (searchTerm.trim() !== '') {
37+
const delayDebounce = setTimeout(() => {
3338
handleSearch()
34-
} else {
35-
setSearchResult([])
36-
}
39+
}, 300) // Add a debounce to reduce API calls
40+
41+
return () => clearTimeout(delayDebounce)
3742
}, [searchTerm])
3843

3944
const handleInputChange = event => {
4045
setSearchTerm(event.target.value)
4146
}
4247

43-
const filteredResults = searchResult.filter(
44-
item =>
45-
item.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
46-
(item.manufactured_by &&
47-
item.manufactured_by.owner_name
48-
.toLowerCase()
49-
.includes(searchTerm.toLowerCase())) ||
50-
item.dpp_class.toLowerCase().includes(searchTerm.toLowerCase())
51-
)
48+
const handleBlur = () => {
49+
setShowSearchResults(false)
50+
}
5251

5352
const handleSearchBoxSelect = () => {
5453
setShowSearchResults(true)
5554
}
5655

57-
const handleBlur = () => {
58-
setShowSearchResults(false)
59-
}
60-
6156
const handleSearchSelect = url => {
6257
router.push(url)
6358
handleBlur()
@@ -82,17 +77,17 @@ export default function SearchBar({ className, ...props }) {
8277
</div>
8378
{showSearchResults && (
8479
<>
85-
{filteredResults.length > 0 && (
80+
{searchResult.length > 0 && (
8681
<ul
8782
className={`absolute left-0 top-16 w-full cursor-pointer rounded-md border border-transparent bg-white text-blue-900 shadow-lg`}
8883
>
89-
{filteredResults.map((item, index) => {
84+
{searchResult.map((item, index) => {
9085
if (!item) {
9186
return null
9287
}
9388

9489
const uniqueKey = item._id || item.name + item.dpp_class + index
95-
console.log(item)
90+
9691
return (
9792
<li
9893
key={uniqueKey}

src/components/UI/Forms/UserDropdown.jsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ export default function DropdownMenu() {
5858
<Menu.Item>
5959
{({ active }) => (
6060
<Link
61-
href='/profile'
61+
href={`/user/${session.user._id}`} // Link to your account settings page
6262
className={classNames(
6363
active ? 'bg-gray-100 text-gray-900' : 'text-gray-700',
6464
'block px-4 py-2 text-sm'
6565
)}
6666
>
6767
<div className='flex flex-row items-center space-x-4'>
68-
<Cog6ToothIcon className='h-5 text-gray-800' />
69-
<p>Account settings</p>
68+
<UserIcon className='h-5 text-gray-800' />
69+
<p>My Profile</p>
7070
</div>
7171
</Link>
7272
)}
@@ -85,8 +85,8 @@ export default function DropdownMenu() {
8585
)}
8686
>
8787
<div className='flex flex-row items-center space-x-4'>
88-
<ExclamationCircleIcon className='h-5 text-gray-800' />
89-
<p>Example link</p>
88+
<Cog6ToothIcon className='h-5 text-gray-800' />
89+
<p>Settings</p>
9090
</div>
9191
</Link>
9292
)}

src/components/UI/global/SearchResultCard.jsx

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import Link from 'next/link'
22
export default function SearchResultCard({ item }) {
3+
const cid = item.cid
34
console.log(item)
4-
const { name, dpp_class, manufactured_by, created_at } = item
5-
65
return (
7-
<Link className='w-full' href={`/product/${item._id}`} passHref>
6+
<Link className='w-full' href={`/product/${cid}`} passHref>
87
<div className='flex w-full cursor-pointer items-center space-x-3 rounded-md p-3 hover:bg-gray-50'>
98
<div className='relative'></div>
10-
<div className='flex flex-col'>
11-
<p className='font-semibold'>{name}</p>
12-
<p className='text-xs font-medium text-gray-500'>
13-
{manufactured_by && manufactured_by.owner_name && (
14-
<span> {manufactured_by.owner_name}</span>
15-
)}
16-
</p>
9+
<div className='flex flex-grow flex-row items-center justify-between'>
10+
<div>
11+
<p className='font-semibold'>{item.ProductName}</p>
12+
<p className='text-xs font-medium text-gray-500'>
13+
<span>{item.Entrydate} </span>
14+
</p>
15+
</div>
16+
<div className='flex flex-col text-right'>
17+
<p className='text-sm font-bold'>CID</p>
18+
<p className='text-xs font-medium text-gray-500'>{item.cid}</p>
19+
</div>
1720
</div>
1821
</div>
1922
</Link>

0 commit comments

Comments
 (0)