price history + manage wish in single product page

This commit is contained in:
hamid zarghami
2025-09-17 16:06:25 +03:30
parent f849ebdb42
commit 7b51a18a4a
8 changed files with 686 additions and 29 deletions
+372
View File
@@ -36,6 +36,7 @@
"react-multi-date-picker": "^4.5.2",
"react-otp-input": "^3.1.1",
"react-spinners": "^0.17.0",
"recharts": "^3.2.1",
"swiper": "^11.2.10",
"tailwind-merge": "^3.3.1",
"yup": "^1.7.0",
@@ -1779,6 +1780,32 @@
"react-dom": "^19.0.0"
}
},
"node_modules/@reduxjs/toolkit": {
"version": "2.9.0",
"resolved": "https://registry.npmjs.org/@reduxjs/toolkit/-/toolkit-2.9.0.tgz",
"integrity": "sha512-fSfQlSRu9Z5yBkvsNhYF2rPS8cGXn/TZVrlwN1948QyZ8xMZ0JvP50S2acZNaf+o63u6aEeMjipFyksjIcWrog==",
"license": "MIT",
"dependencies": {
"@standard-schema/spec": "^1.0.0",
"@standard-schema/utils": "^0.3.0",
"immer": "^10.0.3",
"redux": "^5.0.1",
"redux-thunk": "^3.1.0",
"reselect": "^5.1.0"
},
"peerDependencies": {
"react": "^16.9.0 || ^17.0.0 || ^18 || ^19",
"react-redux": "^7.2.1 || ^8.1.3 || ^9.0.0"
},
"peerDependenciesMeta": {
"react": {
"optional": true
},
"react-redux": {
"optional": true
}
}
},
"node_modules/@rtsao/scc": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@rtsao/scc/-/scc-1.1.0.tgz",
@@ -1793,6 +1820,12 @@
"dev": true,
"license": "MIT"
},
"node_modules/@standard-schema/spec": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.0.0.tgz",
"integrity": "sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==",
"license": "MIT"
},
"node_modules/@standard-schema/utils": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@standard-schema/utils/-/utils-0.3.0.tgz",
@@ -2148,6 +2181,69 @@
"tslib": "^2.4.0"
}
},
"node_modules/@types/d3-array": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/@types/d3-array/-/d3-array-3.2.2.tgz",
"integrity": "sha512-hOLWVbm7uRza0BYXpIIW5pxfrKe0W+D5lrFiAEYR+pb6w3N2SwSMaJbXdUfSEv+dT4MfHBLtn5js0LAWaO6otw==",
"license": "MIT"
},
"node_modules/@types/d3-color": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/@types/d3-color/-/d3-color-3.1.3.tgz",
"integrity": "sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A==",
"license": "MIT"
},
"node_modules/@types/d3-ease": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@types/d3-ease/-/d3-ease-3.0.2.tgz",
"integrity": "sha512-NcV1JjO5oDzoK26oMzbILE6HW7uVXOHLQvHshBUW4UMdZGfiY6v5BeQwh9a9tCzv+CeefZQHJt5SRgK154RtiA==",
"license": "MIT"
},
"node_modules/@types/d3-interpolate": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@types/d3-interpolate/-/d3-interpolate-3.0.4.tgz",
"integrity": "sha512-mgLPETlrpVV1YRJIglr4Ez47g7Yxjl1lj7YKsiMCb27VJH9W8NVM6Bb9d8kkpG/uAQS5AmbA48q2IAolKKo1MA==",
"license": "MIT",
"dependencies": {
"@types/d3-color": "*"
}
},
"node_modules/@types/d3-path": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@types/d3-path/-/d3-path-3.1.1.tgz",
"integrity": "sha512-VMZBYyQvbGmWyWVea0EHs/BwLgxc+MKi1zLDCONksozI4YJMcTt8ZEuIR4Sb1MMTE8MMW49v0IwI5+b7RmfWlg==",
"license": "MIT"
},
"node_modules/@types/d3-scale": {
"version": "4.0.9",
"resolved": "https://registry.npmjs.org/@types/d3-scale/-/d3-scale-4.0.9.tgz",
"integrity": "sha512-dLmtwB8zkAeO/juAMfnV+sItKjlsw2lKdZVVy6LRr0cBmegxSABiLEpGVmSJJ8O08i4+sGR6qQtb6WtuwJdvVw==",
"license": "MIT",
"dependencies": {
"@types/d3-time": "*"
}
},
"node_modules/@types/d3-shape": {
"version": "3.1.7",
"resolved": "https://registry.npmjs.org/@types/d3-shape/-/d3-shape-3.1.7.tgz",
"integrity": "sha512-VLvUQ33C+3J+8p+Daf+nYSOsjB4GXp19/S/aGo60m9h1v6XaxjiT82lKVWJCfzhtuZ3yD7i/TPeC/fuKLLOSmg==",
"license": "MIT",
"dependencies": {
"@types/d3-path": "*"
}
},
"node_modules/@types/d3-time": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@types/d3-time/-/d3-time-3.0.4.tgz",
"integrity": "sha512-yuzZug1nkAAaBlBBikKZTgzCeA+k1uy4ZFwWANOfKw5z5LRhV0gNA7gNkKm7HoK+HRN0wX3EkxGk0fpbWhmB7g==",
"license": "MIT"
},
"node_modules/@types/d3-timer": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@types/d3-timer/-/d3-timer-3.0.2.tgz",
"integrity": "sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw==",
"license": "MIT"
},
"node_modules/@types/estree": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
@@ -2222,6 +2318,12 @@
"@types/react": "^19.0.0"
}
},
"node_modules/@types/use-sync-external-store": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz",
"integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==",
"license": "MIT"
},
"node_modules/@typescript-eslint/eslint-plugin": {
"version": "8.38.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.38.0.tgz",
@@ -3350,6 +3452,127 @@
"devOptional": true,
"license": "MIT"
},
"node_modules/d3-array": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-3.2.4.tgz",
"integrity": "sha512-tdQAmyA18i4J7wprpYq8ClcxZy3SC31QMeByyCFyRt7BVHdREQZ5lpzoe5mFEYZUWe+oq8HBvk9JjpibyEV4Jg==",
"license": "ISC",
"dependencies": {
"internmap": "1 - 2"
},
"engines": {
"node": ">=12"
}
},
"node_modules/d3-color": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.1.0.tgz",
"integrity": "sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==",
"license": "ISC",
"engines": {
"node": ">=12"
}
},
"node_modules/d3-ease": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-3.0.1.tgz",
"integrity": "sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==",
"license": "BSD-3-Clause",
"engines": {
"node": ">=12"
}
},
"node_modules/d3-format": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/d3-format/-/d3-format-3.1.0.tgz",
"integrity": "sha512-YyUI6AEuY/Wpt8KWLgZHsIU86atmikuoOmCfommt0LYHiQSPjvX2AcFc38PX0CBpr2RCyZhjex+NS/LPOv6YqA==",
"license": "ISC",
"engines": {
"node": ">=12"
}
},
"node_modules/d3-interpolate": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-3.0.1.tgz",
"integrity": "sha512-3bYs1rOD33uo8aqJfKP3JWPAibgw8Zm2+L9vBKEHJ2Rg+viTR7o5Mmv5mZcieN+FRYaAOWX5SJATX6k1PWz72g==",
"license": "ISC",
"dependencies": {
"d3-color": "1 - 3"
},
"engines": {
"node": ">=12"
}
},
"node_modules/d3-path": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/d3-path/-/d3-path-3.1.0.tgz",
"integrity": "sha512-p3KP5HCf/bvjBSSKuXid6Zqijx7wIfNW+J/maPs+iwR35at5JCbLUT0LzF1cnjbCHWhqzQTIN2Jpe8pRebIEFQ==",
"license": "ISC",
"engines": {
"node": ">=12"
}
},
"node_modules/d3-scale": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/d3-scale/-/d3-scale-4.0.2.tgz",
"integrity": "sha512-GZW464g1SH7ag3Y7hXjf8RoUuAFIqklOAq3MRl4OaWabTFJY9PN/E1YklhXLh+OQ3fM9yS2nOkCoS+WLZ6kvxQ==",
"license": "ISC",
"dependencies": {
"d3-array": "2.10.0 - 3",
"d3-format": "1 - 3",
"d3-interpolate": "1.2.0 - 3",
"d3-time": "2.1.1 - 3",
"d3-time-format": "2 - 4"
},
"engines": {
"node": ">=12"
}
},
"node_modules/d3-shape": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/d3-shape/-/d3-shape-3.2.0.tgz",
"integrity": "sha512-SaLBuwGm3MOViRq2ABk3eLoxwZELpH6zhl3FbAoJ7Vm1gofKx6El1Ib5z23NUEhF9AsGl7y+dzLe5Cw2AArGTA==",
"license": "ISC",
"dependencies": {
"d3-path": "^3.1.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/d3-time": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/d3-time/-/d3-time-3.1.0.tgz",
"integrity": "sha512-VqKjzBLejbSMT4IgbmVgDjpkYrNWUYJnbCGo874u7MMKIWsILRX+OpX/gTk8MqjpT1A/c6HY2dCA77ZN0lkQ2Q==",
"license": "ISC",
"dependencies": {
"d3-array": "2 - 3"
},
"engines": {
"node": ">=12"
}
},
"node_modules/d3-time-format": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/d3-time-format/-/d3-time-format-4.1.0.tgz",
"integrity": "sha512-dJxPBlzC7NugB2PDLwo9Q8JiTR3M3e4/XANkreKSUxF8vvXKqm1Yfq4Q5dl8budlunRVlUUaDUgFt7eA8D6NLg==",
"license": "ISC",
"dependencies": {
"d3-time": "1 - 3"
},
"engines": {
"node": ">=12"
}
},
"node_modules/d3-timer": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/d3-timer/-/d3-timer-3.0.1.tgz",
"integrity": "sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==",
"license": "ISC",
"engines": {
"node": ">=12"
}
},
"node_modules/damerau-levenshtein": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz",
@@ -3429,6 +3652,12 @@
}
}
},
"node_modules/decimal.js-light": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/decimal.js-light/-/decimal.js-light-2.5.1.tgz",
"integrity": "sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg==",
"license": "MIT"
},
"node_modules/deep-is": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
@@ -3746,6 +3975,16 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/es-toolkit": {
"version": "1.39.10",
"resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.39.10.tgz",
"integrity": "sha512-E0iGnTtbDhkeczB0T+mxmoVlT4YNweEKBLq7oaU4p11mecdsZpNWOglI4895Vh4usbQ+LsJiuLuI2L0Vdmfm2w==",
"license": "MIT",
"workspaces": [
"docs",
"benchmarks"
]
},
"node_modules/escape-string-regexp": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz",
@@ -4185,6 +4424,12 @@
"node": ">=0.10.0"
}
},
"node_modules/eventemitter3": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
"integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==",
"license": "MIT"
},
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -4661,6 +4906,16 @@
"node": ">= 4"
}
},
"node_modules/immer": {
"version": "10.1.3",
"resolved": "https://registry.npmjs.org/immer/-/immer-10.1.3.tgz",
"integrity": "sha512-tmjF/k8QDKydUlm3mZU+tjM6zeq9/fFpPqH9SzWmBnVVKsPBg/V66qsMwb3/Bo90cgUN+ghdVBess+hPsxUyRw==",
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/immer"
}
},
"node_modules/import-fresh": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz",
@@ -4703,6 +4958,15 @@
"node": ">= 0.4"
}
},
"node_modules/internmap": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/internmap/-/internmap-2.0.3.tgz",
"integrity": "sha512-5Hh7Y1wQbvY5ooGgPbDaL5iYLAPzMTUrjMulskHLH6wnv/A+1q5rgEaiuqEjB+oxGXIVZs1FF+R/KPN3ZSQYYg==",
"license": "ISC",
"engines": {
"node": ">=12"
}
},
"node_modules/is-array-buffer": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.5.tgz",
@@ -6344,6 +6608,29 @@
"react-dom": ">=16.8.6 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/react-redux": {
"version": "9.2.0",
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-9.2.0.tgz",
"integrity": "sha512-ROY9fvHhwOD9ySfrF0wmvu//bKCQ6AeZZq1nJNtbDC+kk5DuSuNX/n6YWYF/SYy7bSba4D4FSz8DJeKY/S/r+g==",
"license": "MIT",
"dependencies": {
"@types/use-sync-external-store": "^0.0.6",
"use-sync-external-store": "^1.4.0"
},
"peerDependencies": {
"@types/react": "^18.2.25 || ^19",
"react": "^18.0 || ^19",
"redux": "^5.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"redux": {
"optional": true
}
}
},
"node_modules/react-remove-scroll": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.7.1.tgz",
@@ -6423,6 +6710,48 @@
}
}
},
"node_modules/recharts": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/recharts/-/recharts-3.2.1.tgz",
"integrity": "sha512-0JKwHRiFZdmLq/6nmilxEZl3pqb4T+aKkOkOi/ZISRZwfBhVMgInxzlYU9D4KnCH3KINScLy68m/OvMXoYGZUw==",
"license": "MIT",
"dependencies": {
"@reduxjs/toolkit": "1.x.x || 2.x.x",
"clsx": "^2.1.1",
"decimal.js-light": "^2.5.1",
"es-toolkit": "^1.39.3",
"eventemitter3": "^5.0.1",
"immer": "^10.1.1",
"react-redux": "8.x.x || 9.x.x",
"reselect": "5.1.1",
"tiny-invariant": "^1.3.3",
"use-sync-external-store": "^1.2.2",
"victory-vendor": "^37.0.2"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-is": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
}
},
"node_modules/redux": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz",
"integrity": "sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==",
"license": "MIT"
},
"node_modules/redux-thunk": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-3.1.0.tgz",
"integrity": "sha512-NW2r5T6ksUKXCabzhL9z+h206HQw/NJkcLm1GPImRQ8IzfXwRGqjVhKJGauHirT0DAuyy6hjdnMZaRoAcy0Klw==",
"license": "MIT",
"peerDependencies": {
"redux": "^5.0.0"
}
},
"node_modules/reflect.getprototypeof": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.10.tgz",
@@ -6467,6 +6796,12 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/reselect": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/reselect/-/reselect-5.1.1.tgz",
"integrity": "sha512-K/BG6eIky/SBpzfHZv/dd+9JBFiS4SWV7FIujVyJRux6e45+73RaUHXLmIR1f7WOMaQ0U1km6qwklRQxpJJY0w==",
"license": "MIT"
},
"node_modules/resolve": {
"version": "1.22.10",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.10.tgz",
@@ -7112,6 +7447,12 @@
"integrity": "sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==",
"license": "MIT"
},
"node_modules/tiny-invariant": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.3.tgz",
"integrity": "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==",
"license": "MIT"
},
"node_modules/tinyglobby": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.14.tgz",
@@ -7449,6 +7790,37 @@
}
}
},
"node_modules/use-sync-external-store": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.5.0.tgz",
"integrity": "sha512-Rb46I4cGGVBmjamjphe8L/UnvJD+uPPtTkNvX5mZgqdbavhI4EbgIWJiIHXJ8bc/i9EQGPRh4DwEURJ552Do0A==",
"license": "MIT",
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
}
},
"node_modules/victory-vendor": {
"version": "37.3.6",
"resolved": "https://registry.npmjs.org/victory-vendor/-/victory-vendor-37.3.6.tgz",
"integrity": "sha512-SbPDPdDBYp+5MJHhBCAyI7wKM3d5ivekigc2Dk2s7pgbZ9wIgIBYGVw4zGHBml/qTFbexrofXW6Gu4noGxrOwQ==",
"license": "MIT AND ISC",
"dependencies": {
"@types/d3-array": "^3.0.3",
"@types/d3-ease": "^3.0.0",
"@types/d3-interpolate": "^3.0.1",
"@types/d3-scale": "^4.0.2",
"@types/d3-shape": "^3.1.0",
"@types/d3-time": "^3.0.0",
"@types/d3-timer": "^3.0.0",
"d3-array": "^3.1.6",
"d3-ease": "^3.0.1",
"d3-interpolate": "^3.0.1",
"d3-scale": "^4.0.2",
"d3-shape": "^3.1.0",
"d3-time": "^3.0.0",
"d3-timer": "^3.0.1"
}
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
+1
View File
@@ -37,6 +37,7 @@
"react-multi-date-picker": "^4.5.2",
"react-otp-input": "^3.1.1",
"react-spinners": "^0.17.0",
"recharts": "^3.2.1",
"swiper": "^11.2.10",
"tailwind-merge": "^3.3.1",
"yup": "^1.7.0",
+87 -28
View File
@@ -1,21 +1,77 @@
'use client'
import { Chart2, Heart, Hierarchy2, Notification, RowHorizontal } from 'iconsax-react'
import { FC, useState } from 'react'
import { FC, useEffect, useState } from 'react'
import { Product } from '@/types/product.types'
import { useAddWishlist, useRemoveWishlist } from '@/app/products/hooks/useProductsData'
import { useSharedStore } from '@/share/store/sharedStore'
import { toast } from '@/components/Toast'
import { useCheckWishProduct } from '../hooks/useProductData'
import { useProductStore } from '../store/Store'
import PriceHistory from './PriceHistory'
interface ActionProductProps {
product: Product
}
const ActionProduct: FC<ActionProductProps> = ({ product }) => {
const { variantId } = useProductStore()
const { isLogin } = useSharedStore()
const [isWishlist, setIsWishlist] = useState(false)
const [isCompare, setIsCompare] = useState(false)
const [isWishlistLoading, setIsWishlistLoading] = useState(false)
const { mutate: addWishlist } = useAddWishlist()
const { mutate: removeWishlist } = useRemoveWishlist()
const { data } = useCheckWishProduct(product._id.toString(), variantId)
const handleWishlist = () => {
setIsWishlist(!isWishlist)
// TODO: API call to add/remove from wishlist
if (!isLogin) return
if (!product._id || !product.default_variant?._id) return
setIsWishlistLoading(true)
if (isWishlist) {
removeWishlist(
{
productId: product._id.toString(),
variantId: variantId
},
{
onSuccess: () => {
setIsWishlist(false)
setIsWishlistLoading(false)
},
onError: () => {
setIsWishlistLoading(false)
}
}
)
} else {
addWishlist(
{
productId: product._id.toString(),
variantId: variantId
},
{
onSuccess: () => {
setIsWishlist(true)
setIsWishlistLoading(false)
},
onError: () => {
setIsWishlistLoading(false)
}
}
)
}
}
useEffect(() => {
if (data) {
setIsWishlist(data?.results?.isInWishlist)
}
}, [data])
const handleCompare = () => {
setIsCompare(!isCompare)
// TODO: API call to add/remove from compare
@@ -30,7 +86,7 @@ const ActionProduct: FC<ActionProductProps> = ({ product }) => {
})
} else {
navigator.clipboard.writeText(window.location.href)
// TODO: Show toast notification
toast('')
}
}
@@ -39,46 +95,49 @@ const ActionProduct: FC<ActionProductProps> = ({ product }) => {
<div className='flex flex-col gap-3'>
<button
onClick={handleWishlist}
className='p-2 rounded-full bg-white/80 backdrop-blur-sm hover:bg-white transition-colors'
title={isWishlist ? 'حذف از علاقه‌مندی‌ها' : 'افزودن به علاقه‌مندی‌ها'}
disabled={!isLogin || isWishlistLoading}
className={`p-2 rounded-full bg-white/80 backdrop-blur-sm transition-colors ${isLogin && !isWishlistLoading ? 'hover:bg-white' : 'opacity-50 cursor-not-allowed'
}`}
title={
!isLogin
? 'برای افزودن به علاقه‌مندی‌ها وارد شوید'
: isWishlist
? 'حذف از علاقه‌مندی‌ها'
: 'افزودن به علاقه‌مندی‌ها'
}
>
<Heart
size={20}
color={isWishlist ? '#ff4757' : '#333333'}
color={isWishlist ? '#000' : '#333333'}
variant={isWishlist ? 'Bold' : 'Outline'}
/>
</button>
<button
onClick={handleCompare}
className='p-2 rounded-full bg-white/80 backdrop-blur-sm hover:bg-white transition-colors'
title={isCompare ? 'حذف از مقایسه' : 'افزودن به مقایسه'}
>
<Hierarchy2
size={20}
color={isCompare ? '#2ed573' : '#333333'}
variant={isCompare ? 'Bold' : 'Outline'}
/>
</button>
<button
onClick={handleShare}
className='p-2 rounded-full bg-white/80 backdrop-blur-sm hover:bg-white transition-colors'
title={'اشتراک‌گذاری'}
>
<Hierarchy2
size={20}
color={'#333333'}
variant={'Outline'}
/>
</button>
{/* <button
onClick={handleShare}
className='p-2 rounded-full bg-white/80 backdrop-blur-sm hover:bg-white transition-colors'
title='اشتراک‌گذاری'
>
<Notification size={20} color='#333333' />
</button>
</button> */}
<PriceHistory productId={product._id.toString()} />
<button
className='p-2 rounded-full bg-white/80 backdrop-blur-sm hover:bg-white transition-colors'
title='گزارش مشکل'
>
<Chart2 size={20} color='#333333' />
</button>
<button
className='p-2 rounded-full bg-white/80 backdrop-blur-sm hover:bg-white transition-colors'
title='گزینه‌های بیشتر'
title='مقایسه کالا'
>
<RowHorizontal size={20} color='#333333' variant='Bulk' />
</button>
+158
View File
@@ -0,0 +1,158 @@
'use client'
import { Chart2 } from 'iconsax-react'
import { FC, useState } from 'react'
import { useGetPriceHistory } from '../hooks/useProductData'
import DefaulModal from '@/components/DefaulModal'
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'
interface PriceHistoryProps {
productId: string
}
const PriceHistory: FC<PriceHistoryProps> = ({ productId }) => {
const [isModalOpen, setIsModalOpen] = useState(false)
const { data } = useGetPriceHistory(productId)
// پردازش داده‌ها برای چارت
const chartData = data?.results?.priceHistory?.[0]?.history?.map(item => ({
date: item.date,
selling_price: item.selling_price,
retail_price: item.retail_price,
shop: item.shop
})) || []
return (
<>
<button
onClick={() => setIsModalOpen(true)}
className='p-2 rounded-full bg-white/80 backdrop-blur-sm hover:bg-white transition-colors'
title='نمودار تغییر قیمت'
>
<Chart2 size={20} color='#333333' />
</button>
<DefaulModal
open={isModalOpen}
close={() => setIsModalOpen(false)}
isHeader={true}
title_header="نمودار تغییر قیمت"
width={600}
>
<div className='p-6'>
{chartData.length > 0 ? (
<div className='h-96 w-full'>
<ResponsiveContainer width="100%" height="100%">
<LineChart
data={chartData}
margin={{
top: 20,
right: 30,
left: 20,
bottom: 20,
}}
>
<CartesianGrid strokeDasharray="3 3" stroke="#e0e7ff" />
<XAxis
dataKey="date"
fontSize={11}
tick={{ fontSize: 9, fill: '#6b7280' }}
tickLine={{ stroke: '#d1d5db' }}
axisLine={{ stroke: '#d1d5db' }}
angle={-45}
textAnchor="end"
height={60}
/>
<YAxis
fontSize={11}
tick={{ fontSize: 9, fill: '#6b7280' }}
tickLine={{ stroke: '#d1d5db' }}
axisLine={{ stroke: '#d1d5db' }}
tickFormatter={(value) => `${(value / 1000).toFixed(0)}k`}
/>
<Tooltip
contentStyle={{
backgroundColor: '#ffffff',
border: '1px solid #e5e7eb',
borderRadius: '12px',
fontSize: '13px',
boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1)',
padding: '12px'
}}
formatter={(value, name) => [
<span key={name} style={{ color: name === 'selling_price' ? '#2563eb' : '#dc2626', fontWeight: 'bold' }}>
{value.toLocaleString()} تومان
</span>,
name === 'selling_price' ? 'قیمت فروش' : 'قیمت خرده'
]}
labelFormatter={(label) => (
<span style={{ color: '#374151', fontWeight: '600' }}>
تاریخ: {label}
</span>
)}
cursor={{ stroke: '#9ca3af', strokeWidth: 1, strokeDasharray: '5 5' }}
/>
<Line
type="monotone"
dataKey="selling_price"
stroke="#2563eb"
strokeWidth={3}
dot={{ fill: '#2563eb', strokeWidth: 2, r: 5, stroke: '#ffffff' }}
activeDot={{
r: 8,
fill: '#2563eb',
stroke: '#ffffff',
strokeWidth: 3,
style: { filter: 'drop-shadow(0 4px 6px rgb(37 99 235 / 0.3))' }
}}
name="قیمت فروش"
connectNulls={false}
/>
<Line
type="monotone"
dataKey="retail_price"
stroke="#dc2626"
strokeWidth={3}
dot={{ fill: '#dc2626', strokeWidth: 2, r: 5, stroke: '#ffffff' }}
activeDot={{
r: 8,
fill: '#dc2626',
stroke: '#ffffff',
strokeWidth: 3,
style: { filter: 'drop-shadow(0 4px 6px rgb(220 38 38 / 0.3))' }
}}
name="قیمت خرده"
connectNulls={false}
/>
</LineChart>
</ResponsiveContainer>
</div>
) : (
<div className='flex items-center justify-center h-96'>
<div className='text-center'>
<div className='w-16 h-16 mx-auto mb-4 bg-gray-100 rounded-full flex items-center justify-center'>
<Chart2 size={32} color='#9ca3af' />
</div>
<p className='text-gray-500 text-lg'>دادهای برای نمایش نمودار وجود ندارد</p>
</div>
</div>
)}
{chartData.length > 0 && (
<div className='mt-6 flex gap-8 justify-center'>
<div className='flex items-center gap-3'>
<div className='w-6 h-1 bg-blue-600 rounded-full'></div>
<span className='text-sm font-medium text-gray-700'>قیمت فروش</span>
</div>
<div className='flex items-center gap-3'>
<div className='w-6 h-1 bg-red-600 rounded-full'></div>
<span className='text-sm font-medium text-gray-700'>قیمت خرده</span>
</div>
</div>
)}
</div>
</DefaulModal>
</>
)
}
export default PriceHistory
+16
View File
@@ -24,3 +24,19 @@ export const useAddQuestion = () => {
mutationFn: api.addQuestion,
});
};
export const useCheckWishProduct = (productId: string, variantId: string) => {
return useQuery({
queryKey: ["check-wish-product", productId, variantId],
queryFn: () => api.checkWishProduct(productId, variantId),
enabled: !!productId && !!variantId,
});
};
export const useGetPriceHistory = (productId: string) => {
return useQuery({
queryKey: ["price-history", productId],
queryFn: () => api.getPriceHistory(productId),
enabled: !!productId,
});
};
+22 -1
View File
@@ -1,6 +1,10 @@
import axios from "@/config/axios";
import { ProductDetailResponse } from "@/types/product.types";
import { AddCommentProps, AddQuestionProps } from "../types/Types";
import {
AddCommentProps,
AddQuestionProps,
PriceHistoryResponse,
} from "../types/Types";
export const getProduct = async (
id: string
@@ -24,3 +28,20 @@ export const addQuestion = async (params: AddQuestionProps) => {
);
return data;
};
export const checkWishProduct = async (
productId: string,
variantId: string
) => {
const { data } = await axios.get(
`/product/${productId}/wishlist/${variantId}`
);
return data;
};
export const getPriceHistory = async (
productId: string
): Promise<PriceHistoryResponse> => {
const { data } = await axios.get(`/product/${productId}/price-history`);
return data;
};
+24
View File
@@ -16,3 +16,27 @@ export type ProductStoreType = {
variantId: string;
setVariantId: (value: string) => void;
};
export type PriceHistoryItem = {
shop: string;
selling_price: number;
retail_price: number;
date: string;
};
export type PriceHistory = {
_id: number;
product: number;
title: string;
history: PriceHistoryItem[];
};
export type PriceHistoryResults = {
priceHistory: PriceHistory[];
};
export type PriceHistoryResponse = {
status: number;
success: boolean;
results: PriceHistoryResults;
};
+6
View File
@@ -7,6 +7,7 @@ import ProductCard from "@/components/ProductCard"
import { useGetWithList } from "../hooks/useProfileData"
import { IProduct } from "@/types/landing.types"
import { WishlistItem } from "../types/ProfileTypes"
import PageLoading from "@/components/PageLoading"
const FavoritePage: NextPage = () => {
@@ -66,6 +67,11 @@ const FavoritePage: NextPage = () => {
const products = withList?.results?.wishlist ? transformWishlistToProducts(withList.results.wishlist) : []
if (isLoading) {
return <PageLoading />
}
return (
<div className="p-3 sm:p-4 md:p-6">
<Menu pageActive='favorite' />