diff --git a/package-lock.json b/package-lock.json index 74ef3f5..05628e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@hookform/resolvers": "^5.2.1", "@radix-ui/react-accordion": "^1.2.11", + "@radix-ui/react-checkbox": "^1.3.3", "@radix-ui/react-popover": "^1.1.15", "@radix-ui/react-radio-group": "^1.3.7", "@radix-ui/react-separator": "^1.1.7", @@ -1123,6 +1124,66 @@ } } }, + "node_modules/@radix-ui/react-checkbox": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@radix-ui/react-checkbox/-/react-checkbox-1.3.3.tgz", + "integrity": "sha512-wBbpv+NQftHDdG86Qc0pIyXk5IR3tM8Vd0nWLKDcX8nNn4nXFOFwsKuqw2okA/1D/mpaAkmuyndrPJTYDNZtFw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.1.3", + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-presence": "1.1.5", + "@radix-ui/react-primitive": "2.1.3", + "@radix-ui/react-use-controllable-state": "1.2.2", + "@radix-ui/react-use-previous": "1.1.1", + "@radix-ui/react-use-size": "1.1.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-checkbox/node_modules/@radix-ui/primitive": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.3.tgz", + "integrity": "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg==", + "license": "MIT" + }, + "node_modules/@radix-ui/react-checkbox/node_modules/@radix-ui/react-presence": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@radix-ui/react-presence/-/react-presence-1.1.5.tgz", + "integrity": "sha512-/jfEwNDdQVBCNvjkGit4h6pMOzq8bHkopq458dPt2lMjx+eBQUohZNG9A7DtO/O5ukSbxuaNGXMjHicgwy6rQQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-use-layout-effect": "1.1.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-collapsible": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/@radix-ui/react-collapsible/-/react-collapsible-1.1.11.tgz", diff --git a/package.json b/package.json index b6c1958..3f1cbea 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "@hookform/resolvers": "^5.2.1", "@radix-ui/react-accordion": "^1.2.11", + "@radix-ui/react-checkbox": "^1.3.3", "@radix-ui/react-popover": "^1.1.15", "@radix-ui/react-radio-group": "^1.3.7", "@radix-ui/react-separator": "^1.1.7", diff --git a/src/app/blogs/[id]/page.tsx b/src/app/blogs/[id]/page.tsx index 39d97c9..8d520e9 100644 --- a/src/app/blogs/[id]/page.tsx +++ b/src/app/blogs/[id]/page.tsx @@ -43,16 +43,14 @@ const BlogDetail: NextPage = () => { const handleNativeShare = async () => { const blog = data?.results?.blog if (blog && currentUrl && typeof navigator !== 'undefined' && 'share' in navigator) { - try { - const shareData = { - title: blog.title_fa, - text: `مشاهده مقاله: ${blog.title_fa}`, - url: currentUrl, - } - await (navigator as { share: (data: typeof shareData) => Promise }).share(shareData) - } catch (error) { - console.log('Error sharing:', error) + + const shareData = { + title: blog.title_fa, + text: `مشاهده مقاله: ${blog.title_fa}`, + url: currentUrl, } + await (navigator as { share: (data: typeof shareData) => Promise }).share(shareData) + } } @@ -97,7 +95,7 @@ const BlogDetail: NextPage = () => {
- {new Date(blog.createdAt).toLocaleDateString('fa-IR')} + {blog.createdAt}
diff --git a/src/app/product/components/ModalReport.tsx b/src/app/product/components/ModalReport.tsx new file mode 100644 index 0000000..632d0ce --- /dev/null +++ b/src/app/product/components/ModalReport.tsx @@ -0,0 +1,121 @@ +import DefaulModal from '@/components/DefaulModal' +import { Button } from '@/components/ui/button' +import { Checkbox } from '@/components/ui/checkbox' +import { InfoCircle } from 'iconsax-react' +import { useState, type FC } from 'react' +import { useGetProductQuestion, useSaveReport } from '../hooks/useProductData' +import { ProductQuestion } from '../types/Types' +import { toast } from '@/components/Toast' + +type Props = { + productId: number + productName?: string +} + +const ModalReport: FC = (props) => { + const { productId, productName } = props + const [isOpen, setIsOpen] = useState(false) + const [selectedOptions, setSelectedOptions] = useState([]) + const [description, setDescription] = useState('') + + const { data: questionsData, isLoading } = useGetProductQuestion(productId.toString()) + const saveReportMutation = useSaveReport() + + const reportOptions = questionsData?.results?.questions || [] + + const handleSubmit = async () => { + if (selectedOptions.length === 0) return + + await saveReportMutation.mutateAsync({ + productId: productId.toString(), + answers: selectedOptions.map(id => ({ questionId: parseInt(id) })), + description: description.trim() || '' + }) + + setIsOpen(false) + setSelectedOptions([]) + setDescription('') + toast('گزارش شما با موفقیت ارسال شد', 'success') + + } + + return ( +
+
setIsOpen(true)} className='mt-6 flex gap-2 cursor-pointer'> + + گزارش نادرستی کالا +
+ + setIsOpen(false)} + title_header='گزارش نادرستی مشخصات' + isHeader + > +
+ {/* Product Name */} + {productName && ( +
+

{productName}

+
+ )} + + {/* Report Options */} +
+ {isLoading ? ( +
+
+
+ ) : ( + reportOptions.map((option: ProductQuestion) => ( +
+ { + if (checked) { + setSelectedOptions(prev => [...prev, option._id.toString()]) + } else { + setSelectedOptions(prev => prev.filter(id => id !== option._id.toString())) + } + }} + /> + +
+ )) + )} +
+ + {/* Description */} +
+

توضیحات

+