Skip to content

Commit

Permalink
feat(search): create product searchbar (#43)
Browse files Browse the repository at this point in the history
* feat(search): create product searchbar

* add missing translations
  • Loading branch information
Clement-Muth authored Oct 24, 2024
1 parent 8186e7f commit a025c71
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 10 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
"ky": "^1.7.2",
"kysely": "^0.27.4",
"lodash": "^4.17.21",
"lucide-react": "^0.259.0",
"lucide-react": "^0.453.0",
"next": "15.0.0",
"next-auth": "beta",
"next-themes": "^0.3.0",
"postcss": "8.4.25",
"react": "^18.3.1",
"react-barcode-scanner": "^2.1.0",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.1",
"react-phone-number-input": "^3.4.9",
Expand Down
6 changes: 4 additions & 2 deletions src/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Trans } from "@lingui/macro";
import Balancer from "react-wrap-balancer";
import { Searchbar } from "~/applications/Searchbar/Ui/Searchbar";
import { withLinguiPage } from "~/core/withLinguiLayout";
import { auth } from "~/libraries/nextauth/authConfig";

Expand All @@ -9,10 +10,11 @@ const HomePage = async () => {
return (
<main className="relative flex flex-1 w-full flex-col items-center justify-center px-4 py-32">
{session?.user ? (
<div className="flex flex-col items-center max-w-2xl">
<h1 className="text-center font-display text-5xl font-bold tracking-[-0.02em] drop-shadow-sm md:text-7xl md:leading-[5rem]">
<div className="flex flex-col items-center max-w-2xl w-full">
<h1 className="text-center font-display text-5xl font-bold tracking-[-0.02em] drop-shadow-sm md:text-4xl md:leading-[5rem]">
<Trans>Hello {session.user.name}</Trans>
</h1>
<Searchbar />
</div>
) : (
<div className="flex flex-col items-center max-w-2xl">
Expand Down
79 changes: 79 additions & 0 deletions src/applications/Searchbar/Ui/Searchbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"use client";

import { t } from "@lingui/macro";
import { useLingui } from "@lingui/react";
import { Button } from "@nextui-org/react";
import { ScanBarcode, Send } from "lucide-react";
import { BarcodeScanner } from "react-barcode-scanner";
import useForm from "~/components/Form/useForm";
import { Input } from "~/components/Inputs/Input/Input";
import "react-barcode-scanner/polyfill";
import { useState } from "react";

export const Searchbar = () => {
const [showScanner, setShowScanner] = useState(false);
const form = useForm<{ search: string }>("search");
const { i18n } = useLingui();

return (
<form.Form
methods={form.methods}
onSubmit={(data) => console.log(data)}
disableActions
className="w-full mt-8"
>
<Input
type="search"
name="search"
radius="full"
size="lg"
placeholder={t(i18n)`Enter your codebar`}
classNames={{ inputWrapper: "px-2" }}
pattern={{
value: /^(?:\d{12}|\d{13}|[A-Z0-9\-\. \$\/\+%]{1,43}|[\x20-\x7E]{1,48})$/,
message: t(i18n)`Please enter a valid barcode.`
}}
startContent={
<Button
startContent={<ScanBarcode />}
variant="light"
radius="full"
onPress={() => setShowScanner(true)}
isIconOnly
/>
}
endContent={
<Button
startContent={<Send />}
type="submit"
color="primary"
radius="full"
isDisabled={!form.watch("search")?.length}
isIconOnly
/>
}
/>
{showScanner ? (
<BarcodeScanner
onCapture={(barcode) => console.log(barcode)}
options={{
formats: [
"codabar",
"upc_a",
"code_128",
"code_39",
"code_93",
"data_matrix",
"ean_13",
"ean_8",
"itf",
"pdf417",
"qr_code",
"upc_e"
]
}}
/>
) : null}
</form.Form>
);
};
8 changes: 8 additions & 0 deletions src/translations/messages/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ msgstr "Display Name"
msgid "Enter a phone number to receive important service updates by SMS."
msgstr "Enter a phone number to receive important service updates by SMS."

#: src/applications/Searchbar/Ui/Searchbar.tsx
msgid "Enter your codebar"
msgstr "Enter your codebar"

#: src/components/Inputs/Phone/Phone.tsx
msgid "Enter your phone number"
msgstr "Enter your phone number"
Expand Down Expand Up @@ -118,6 +122,10 @@ msgstr "Phone Number"
msgid "Phone number updated"
msgstr "Phone number updated"

#: src/applications/Searchbar/Ui/Searchbar.tsx
msgid "Please enter a valid barcode."
msgstr "Please enter a valid barcode."

#: src/applications/Profile/Ui/Settings/DisplayName.tsx
msgid "Please enter your full name, or a display name you are comfortable with."
msgstr "Please enter your full name, or a display name you are comfortable with."
Expand Down
8 changes: 8 additions & 0 deletions src/translations/messages/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ msgstr "Nom d'affichage"
msgid "Enter a phone number to receive important service updates by SMS."
msgstr "Entrez un numéro de téléphone pour recevoir des mises à jour importantes du service par SMS."

#: src/applications/Searchbar/Ui/Searchbar.tsx
msgid "Enter your codebar"
msgstr "Entrez votre code-barres"

#: src/components/Inputs/Phone/Phone.tsx
msgid "Enter your phone number"
msgstr "Entrez votre numéro de téléphone"
Expand Down Expand Up @@ -118,6 +122,10 @@ msgstr "Numéro de téléphone"
msgid "Phone number updated"
msgstr "Numéro de téléphone mis à jour"

#: src/applications/Searchbar/Ui/Searchbar.tsx
msgid "Please enter a valid barcode."
msgstr "Veuillez entrer un code-barres valide."

#: src/applications/Profile/Ui/Settings/DisplayName.tsx
msgid "Please enter your full name, or a display name you are comfortable with."
msgstr "Veuillez entrer votre nom complet, ou un nom d'affichage avec lequel vous êtes à l'aise"
Expand Down
61 changes: 54 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4407,6 +4407,15 @@ __metadata:
languageName: node
linkType: hard

"@preflower/barcode-detector-polyfill@npm:^0.9.20":
version: 0.9.20
resolution: "@preflower/barcode-detector-polyfill@npm:0.9.20"
dependencies:
"@undecaf/zbar-wasm": ^0.10.1
checksum: 8b9b4ead477203d0eb1a903f7a6279139cfc4209b8a47b2727ccbdbbce5c2281e73881b93b9e4089608870473abdc99efb404d6e264f71d7399b36381c9f4322
languageName: node
linkType: hard

"@prisma/adapter-neon@npm:^5.21.1":
version: 5.21.1
resolution: "@prisma/adapter-neon@npm:5.21.1"
Expand Down Expand Up @@ -7299,6 +7308,13 @@ __metadata:
languageName: node
linkType: hard

"@undecaf/zbar-wasm@npm:^0.10.1":
version: 0.10.1
resolution: "@undecaf/zbar-wasm@npm:0.10.1"
checksum: cd1a28fb898a22045b2fa42db8889c8d7c664b90ea783d8759c60667c2c1b345d735f930485906199f5a13f99870de8e4ee94b4be46547e8ce452afae153bfe9
languageName: node
linkType: hard

"@vercel/blob@npm:^0.25.1":
version: 0.25.1
resolution: "@vercel/blob@npm:0.25.1"
Expand Down Expand Up @@ -13015,12 +13031,12 @@ __metadata:
languageName: node
linkType: hard

"lucide-react@npm:^0.259.0":
version: 0.259.0
resolution: "lucide-react@npm:0.259.0"
"lucide-react@npm:^0.453.0":
version: 0.453.0
resolution: "lucide-react@npm:0.453.0"
peerDependencies:
react: ^16.5.1 || ^17.0.0 || ^18.0.0
checksum: d760b2af40e36393e2f72beca3162eb8ab264e09fba8660649b7f955ecee38d2d7242ea513f7249c3d97a937b02257c3ee20af5d82d4f77509e3f143da7d009d
react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0-rc
checksum: 1a48153fd9338266d8bb14c735bfe8bfb046c505ab91421586cbae0a8ac1924536e813d430d1f91c883bb4ea67f0664bfca273f58e478438f0ad8f8f09fced76
languageName: node
linkType: hard

Expand Down Expand Up @@ -14463,13 +14479,14 @@ __metadata:
kysely-codegen: ^0.17.0
lint-staged: ^15.2.10
lodash: ^4.17.21
lucide-react: ^0.259.0
lucide-react: ^0.453.0
next: 15.0.0
next-auth: beta
next-themes: ^0.3.0
postcss: 8.4.25
prisma: ^5.21.1
react: ^18.3.1
react-barcode-scanner: ^2.1.0
react-dom: ^18.3.1
react-hook-form: ^7.53.1
react-phone-number-input: ^3.4.9
Expand Down Expand Up @@ -15050,6 +15067,20 @@ __metadata:
languageName: node
linkType: hard

"react-barcode-scanner@npm:^2.1.0":
version: 2.1.0
resolution: "react-barcode-scanner@npm:2.1.0"
dependencies:
"@preflower/barcode-detector-polyfill": ^0.9.20
tslib: ^2.6.3
webrtc-adapter: ^9.0.1
peerDependencies:
react: "*"
react-dom: "*"
checksum: 823036fa4811fc4a16bb0e0f11dfa969282677c5f374d4b9bdb3d2cc9c9861f73a13d637e7cdca6b41f1d38faff2a53a1fa6497fe18c5c38b73585c128927669
languageName: node
linkType: hard

"react-dom@npm:^18.3.1":
version: 18.3.1
resolution: "react-dom@npm:18.3.1"
Expand Down Expand Up @@ -15797,6 +15828,13 @@ __metadata:
languageName: node
linkType: hard

"sdp@npm:^3.2.0":
version: 3.2.0
resolution: "sdp@npm:3.2.0"
checksum: 227885bddab9a5845e56ae184ff51e43ec7bc155e7f1ed2f17ca1b012e6767011d5bd01b6c4064ded8e3b6f6bf3c9b26b2cf754b9c8662285988ed27b54f37b1
languageName: node
linkType: hard

"semantic-release@npm:^24.1.0":
version: 24.1.3
resolution: "semantic-release@npm:24.1.3"
Expand Down Expand Up @@ -17056,7 +17094,7 @@ __metadata:
languageName: node
linkType: hard

"tslib@npm:^2.0.0, tslib@npm:^2.1.0, tslib@npm:^2.4.0, tslib@npm:^2.7.0":
"tslib@npm:^2.0.0, tslib@npm:^2.1.0, tslib@npm:^2.4.0, tslib@npm:^2.6.3, tslib@npm:^2.7.0":
version: 2.8.0
resolution: "tslib@npm:2.8.0"
checksum: de852ecd81adfdb4870927e250763345f07dc13fe7f395ce261424966bb122a0992ad844c3ec875c9e63e72afe2220a150712984e44dfd1a8a7e538a064e3d46
Expand Down Expand Up @@ -17752,6 +17790,15 @@ __metadata:
languageName: node
linkType: hard

"webrtc-adapter@npm:^9.0.1":
version: 9.0.1
resolution: "webrtc-adapter@npm:9.0.1"
dependencies:
sdp: ^3.2.0
checksum: b9a5d24dc43e00f5fb5423d4f5974ddfd6d45019eea374e8fb947560a820d66ad7ab5bee976c734b3db4ff09641be8a362e3e800b5906a5e81c6dbb155cc4256
languageName: node
linkType: hard

"whatwg-encoding@npm:^2.0.0":
version: 2.0.0
resolution: "whatwg-encoding@npm:2.0.0"
Expand Down

0 comments on commit a025c71

Please sign in to comment.