diff --git a/client/package-lock.json b/client/package-lock.json index 1d9b8a6..3e1c44d 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "@minimal/material-kit-react", "version": "1.8.0", + "license": "MIT", "dependencies": { "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", @@ -29,8 +30,9 @@ "react-apexcharts": "^1.4.1", "react-dom": "^18.2.0", "react-helmet-async": "^1.3.0", - "react-hook-form": "^7.47.0", + "react-hook-form": "^7.48.2", "react-pdf-viewer": "^0.1.0", + "react-query": "^3.39.3", "react-router-dom": "^6.16.0", "simplebar-react": "^3.2.4" }, @@ -2392,7 +2394,6 @@ "version": "1.6.51", "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", - "dev": true, "engines": { "node": ">=0.6" } @@ -2551,6 +2552,21 @@ "node": ">=8" } }, + "node_modules/broadcast-channel": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/broadcast-channel/-/broadcast-channel-3.7.0.tgz", + "integrity": "sha512-cIAKJXAxGJceNZGTZSBzMxzyOn72cVgPnKx4dc6LRjQgbaJUQqhy5rzL3zbMxkMWsGKkv2hSFkPRMEXfoMZ2Mg==", + "dependencies": { + "@babel/runtime": "^7.7.2", + "detect-node": "^2.1.0", + "js-sha3": "0.8.0", + "microseconds": "0.2.0", + "nano-time": "1.0.0", + "oblivious-set": "1.0.0", + "rimraf": "3.0.2", + "unload": "2.2.0" + } + }, "node_modules/brorand": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", @@ -6789,6 +6805,11 @@ "set-function-name": "^2.0.1" } }, + "node_modules/js-sha3": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", + "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -7146,6 +7167,15 @@ "node": ">=0.10.0" } }, + "node_modules/match-sorter": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/match-sorter/-/match-sorter-6.3.1.tgz", + "integrity": "sha512-mxybbo3pPNuA+ZuCUhm5bwNkXrJTbsk5VWbR5wiwz/GC6LIiegBGn2w3O08UG/jdbYLinw51fSQ5xNU1U3MgBw==", + "dependencies": { + "@babel/runtime": "^7.12.5", + "remove-accents": "0.4.2" + } + }, "node_modules/md5.js": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", @@ -7506,6 +7536,11 @@ "node": ">=8.6" } }, + "node_modules/microseconds": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/microseconds/-/microseconds-0.2.0.tgz", + "integrity": "sha512-n7DHHMjR1avBbSpsTBj6fmMGh2AGrifVV4e+WYc3Q9lO+xnSZ3NyhcBND3vzzatt05LFhoKFRxrIyklmLlUtyA==" + }, "node_modules/miller-rabin": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz", @@ -7724,6 +7759,14 @@ "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==", "optional": true }, + "node_modules/nano-time": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/nano-time/-/nano-time-1.0.0.tgz", + "integrity": "sha512-flnngywOoQ0lLQOTRNexn2gGSNuM9bKj9RZAWSzhQ+UJYaAFG9bac4DW9VHjUAzrOaIcajHybCTHe/bkvozQqA==", + "dependencies": { + "big-integer": "^1.6.16" + } + }, "node_modules/nanoid": { "version": "3.3.6", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", @@ -8171,6 +8214,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/oblivious-set": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/oblivious-set/-/oblivious-set-1.0.0.tgz", + "integrity": "sha512-z+pI07qxo4c2CulUHCDf9lcqDlMSo72N/4rLUpRXf6fu+q8vjt8y0xS+Tlf8NTJDdTXHbdeO1n3MlbctwEoXZw==" + }, "node_modules/obuf": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz", @@ -9085,9 +9133,9 @@ } }, "node_modules/react-hook-form": { - "version": "7.47.0", - "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.47.0.tgz", - "integrity": "sha512-F/TroLjTICipmHeFlMrLtNLceO2xr1jU3CyiNla5zdwsGUGu2UOxxR4UyJgLlhMwLW/Wzp4cpJ7CPfgJIeKdSg==", + "version": "7.48.2", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.48.2.tgz", + "integrity": "sha512-H0T2InFQb1hX7qKtDIZmvpU1Xfn/bdahWBN1fH19gSe4bBEqTfmlr7H3XWTaVtiK4/tpPaI1F3355GPMZYge+A==", "engines": { "node": ">=12.22.0" }, @@ -9169,6 +9217,31 @@ "object-assign": "^4.1.1" } }, + "node_modules/react-query": { + "version": "3.39.3", + "resolved": "https://registry.npmjs.org/react-query/-/react-query-3.39.3.tgz", + "integrity": "sha512-nLfLz7GiohKTJDuT4us4X3h/8unOh+00MLb2yJoGTPjxKs2bc1iDhkNx2bd5MKklXnOD3NrVZ+J2UXujA5In4g==", + "dependencies": { + "@babel/runtime": "^7.5.5", + "broadcast-channel": "^3.4.1", + "match-sorter": "^6.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + }, + "react-native": { + "optional": true + } + } + }, "node_modules/react-router": { "version": "6.16.0", "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.16.0.tgz", @@ -9376,6 +9449,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/remove-accents": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/remove-accents/-/remove-accents-0.4.2.tgz", + "integrity": "sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==" + }, "node_modules/remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", @@ -9508,7 +9586,6 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "devOptional": true, "dependencies": { "glob": "^7.1.3" }, @@ -11215,6 +11292,15 @@ "node": ">= 10.0.0" } }, + "node_modules/unload": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/unload/-/unload-2.2.0.tgz", + "integrity": "sha512-B60uB5TNBLtN6/LsgAf3udH9saB5p7gqJwcFfbOEZ8BcBHnGwCf6G/TGiEqkRAxX7zAFIUtzdrXQSdL3Q/wqNA==", + "dependencies": { + "@babel/runtime": "^7.6.2", + "detect-node": "^2.0.4" + } + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -14528,8 +14614,7 @@ "big-integer": { "version": "1.6.51", "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", - "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", - "dev": true + "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==" }, "big.js": { "version": "5.2.2", @@ -14658,6 +14743,21 @@ "fill-range": "^7.0.1" } }, + "broadcast-channel": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/broadcast-channel/-/broadcast-channel-3.7.0.tgz", + "integrity": "sha512-cIAKJXAxGJceNZGTZSBzMxzyOn72cVgPnKx4dc6LRjQgbaJUQqhy5rzL3zbMxkMWsGKkv2hSFkPRMEXfoMZ2Mg==", + "requires": { + "@babel/runtime": "^7.7.2", + "detect-node": "^2.1.0", + "js-sha3": "0.8.0", + "microseconds": "0.2.0", + "nano-time": "1.0.0", + "oblivious-set": "1.0.0", + "rimraf": "3.0.2", + "unload": "2.2.0" + } + }, "brorand": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", @@ -17911,6 +18011,11 @@ "set-function-name": "^2.0.1" } }, + "js-sha3": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", + "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -18186,6 +18291,15 @@ "object-visit": "^1.0.0" } }, + "match-sorter": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/match-sorter/-/match-sorter-6.3.1.tgz", + "integrity": "sha512-mxybbo3pPNuA+ZuCUhm5bwNkXrJTbsk5VWbR5wiwz/GC6LIiegBGn2w3O08UG/jdbYLinw51fSQ5xNU1U3MgBw==", + "requires": { + "@babel/runtime": "^7.12.5", + "remove-accents": "0.4.2" + } + }, "md5.js": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", @@ -18481,6 +18595,11 @@ "picomatch": "^2.3.1" } }, + "microseconds": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/microseconds/-/microseconds-0.2.0.tgz", + "integrity": "sha512-n7DHHMjR1avBbSpsTBj6fmMGh2AGrifVV4e+WYc3Q9lO+xnSZ3NyhcBND3vzzatt05LFhoKFRxrIyklmLlUtyA==" + }, "miller-rabin": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz", @@ -18643,6 +18762,14 @@ "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==", "optional": true }, + "nano-time": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/nano-time/-/nano-time-1.0.0.tgz", + "integrity": "sha512-flnngywOoQ0lLQOTRNexn2gGSNuM9bKj9RZAWSzhQ+UJYaAFG9bac4DW9VHjUAzrOaIcajHybCTHe/bkvozQqA==", + "requires": { + "big-integer": "^1.6.16" + } + }, "nanoid": { "version": "3.3.6", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", @@ -18986,6 +19113,11 @@ "es-abstract": "^1.20.4" } }, + "oblivious-set": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/oblivious-set/-/oblivious-set-1.0.0.tgz", + "integrity": "sha512-z+pI07qxo4c2CulUHCDf9lcqDlMSo72N/4rLUpRXf6fu+q8vjt8y0xS+Tlf8NTJDdTXHbdeO1n3MlbctwEoXZw==" + }, "obuf": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz", @@ -19666,9 +19798,9 @@ } }, "react-hook-form": { - "version": "7.47.0", - "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.47.0.tgz", - "integrity": "sha512-F/TroLjTICipmHeFlMrLtNLceO2xr1jU3CyiNla5zdwsGUGu2UOxxR4UyJgLlhMwLW/Wzp4cpJ7CPfgJIeKdSg==", + "version": "7.48.2", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.48.2.tgz", + "integrity": "sha512-H0T2InFQb1hX7qKtDIZmvpU1Xfn/bdahWBN1fH19gSe4bBEqTfmlr7H3XWTaVtiK4/tpPaI1F3355GPMZYge+A==", "requires": {} }, "react-is": { @@ -19729,6 +19861,16 @@ } } }, + "react-query": { + "version": "3.39.3", + "resolved": "https://registry.npmjs.org/react-query/-/react-query-3.39.3.tgz", + "integrity": "sha512-nLfLz7GiohKTJDuT4us4X3h/8unOh+00MLb2yJoGTPjxKs2bc1iDhkNx2bd5MKklXnOD3NrVZ+J2UXujA5In4g==", + "requires": { + "@babel/runtime": "^7.5.5", + "broadcast-channel": "^3.4.1", + "match-sorter": "^6.0.2" + } + }, "react-router": { "version": "6.16.0", "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.16.0.tgz", @@ -19881,6 +20023,11 @@ "set-function-name": "^2.0.0" } }, + "remove-accents": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/remove-accents/-/remove-accents-0.4.2.tgz", + "integrity": "sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==" + }, "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", @@ -19977,7 +20124,6 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "devOptional": true, "requires": { "glob": "^7.1.3" } @@ -21324,6 +21470,15 @@ "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", "dev": true }, + "unload": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/unload/-/unload-2.2.0.tgz", + "integrity": "sha512-B60uB5TNBLtN6/LsgAf3udH9saB5p7gqJwcFfbOEZ8BcBHnGwCf6G/TGiEqkRAxX7zAFIUtzdrXQSdL3Q/wqNA==", + "requires": { + "@babel/runtime": "^7.6.2", + "detect-node": "^2.0.4" + } + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/client/package.json b/client/package.json index eebe78f..4993d63 100644 --- a/client/package.json +++ b/client/package.json @@ -1,27 +1,7 @@ { "name": "@minimal/material-kit-react", "author": "minimals.cc", - "licence": "MIT", - "version": "1.8.0", - "private": false, - "scripts": { - "dev": "vite", - "start": "vite preview", - "build": "vite build", - "lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"", - "lint:fix": "eslint --fix \"src/**/*.{js,jsx,ts,tsx}\"", - "prettier": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"", - "rm:all": "rm -rf node_modules .next out dist build", - "re:start": "yarn rm:all && yarn install && yarn dev", - "re:build": "yarn rm:all && yarn install && yarn build", - "re:build-npm": "npm run rm:all && npm install && npm run build", - "dev:host": "vite --host", - "vite:start": "vite", - "vite:build": "vite build" - }, - "name": "@minimal/material-kit-react", - "author": "minimals.cc", - "licence": "MIT", + "license": "MIT", "version": "1.8.0", "private": false, "scripts": { diff --git a/client/src/app.jsx b/client/src/app.jsx index f65b26b..79a122e 100644 --- a/client/src/app.jsx +++ b/client/src/app.jsx @@ -16,3 +16,5 @@ export default function App() { ); } + + diff --git a/client/src/routes/sections.jsx b/client/src/routes/sections.jsx index 5f15108..d3ee4ab 100644 --- a/client/src/routes/sections.jsx +++ b/client/src/routes/sections.jsx @@ -3,7 +3,7 @@ import { Outlet, Navigate, useRoutes } from 'react-router-dom'; import DashboardLayout from 'src/layouts/dashboard'; -import UploadFile from 'src/sections/upload/oneUpload'; +import UploadFile from 'src/sections/upload/Upload'; export const IndexPage = lazy(() => import('src/pages/app')); export const BlogPage = lazy(() => import('src/pages/blog')); diff --git a/client/src/sections/register/register-view.jsx b/client/src/sections/register/register-view.jsx index 1c4df88..52a7691 100644 --- a/client/src/sections/register/register-view.jsx +++ b/client/src/sections/register/register-view.jsx @@ -20,6 +20,8 @@ import { useRouter } from 'src/routes/hooks'; import { bgGradient } from 'src/theme/css'; import Logo from 'src/components/logo'; +import { axiosInstance } from '../../utils/axiosInstance'; +import RegistrationUpload from 'src/sections/upload/registrationUpload'; // ---------------------------------------------------------------------- @@ -229,6 +231,7 @@ export default function RegisterView() { error={!!errors?.specialty} helperText={errors?.specialty ? 'Required' : null} /> + )} diff --git a/client/src/sections/upload/oneUpload.jsx b/client/src/sections/upload/Upload.jsx similarity index 59% rename from client/src/sections/upload/oneUpload.jsx rename to client/src/sections/upload/Upload.jsx index 9fc85f0..86babe5 100644 --- a/client/src/sections/upload/oneUpload.jsx +++ b/client/src/sections/upload/Upload.jsx @@ -6,15 +6,41 @@ import InputAdornment from '@mui/material/InputAdornment'; import IconButton from '@mui/material/IconButton'; import CloudUploadIcon from '@mui/icons-material/CloudUpload'; import PropTypes from 'prop-types'; +import { axiosInstance } from '../../utils/axiosInstance'; +import Label from 'src/components/label'; -export default function UploadFile({ url }) { +function Upload({ url, field, handleUploadSuccess }) { const [files, setFiles] = useState([]); const [feedback, setFeedback] = useState(""); const [isFileChanged, setIsFileChanged] = useState(false); + const [labelColor, setLabelColor] = useState('green'); + + const isAllowed = (files) => { + let len = files.length; + // console.log(files, "++++"); + const allowedTypes = ['image/png', 'image/jpg', 'image/jpeg', 'application/pdf']; + if (len > 10) { + return false; + } + while (len > 0) { + len -= 1; + console.log(files[len], "------", len); + if (!allowedTypes.includes(files[len].type)) + return false; + } + return true; + }; const handleFileChange = (event) => { const selectedFiles = event.target.files; + if (!isAllowed(selectedFiles)) { + setFeedback("maximum of 10 PDFs or images(png,jpg,jpeg) are allowed "); + setLabelColor('red'); + return; + } + + console.log(selectedFiles); setFiles(selectedFiles); setIsFileChanged(true); }; @@ -23,38 +49,45 @@ export default function UploadFile({ url }) { const handleUpload = async () => { const formData = new FormData(); let len = files.length; - while (len >= 0) { + while (len > 0) { len -= 1; - formData.append('medicalHistory', files[len]); + formData.append(field, files[len]); } if (!files) { setFeedback("Choose a files"); + setLabelColor(red); return; } if (!isFileChanged) { setFeedback("File is already uploaded"); + setLabelColor(red); + return; } try { - const res = await axios.post(url, formData, { + const res = await axiosInstance.post(url, formData, { headers: { "Content-Type": "multipart/form-data", } - }); - + }) + if (res.status == 200) { + handleUploadSuccess(field); + } + setLabelColor(res.status === 200 ? 'green' : 'red'); setFeedback(res.status === 200 ? "Uploaded successfully" : "Failed to upload"); setIsFileChanged(false); } catch (error) { setFeedback("Failed to upload"); + setLabelColor('red'); } }; return ( -
+
} /> -

{feedback}

+ + + +

+
); } -UploadFile.propTypes = { +Upload.propTypes = { url: PropTypes.string.isRequired, -}; \ No newline at end of file +}; + +export default Upload; \ No newline at end of file diff --git a/client/src/sections/upload/displayRecords.jsx b/client/src/sections/upload/displayRecords.jsx index d3c932f..376c355 100644 --- a/client/src/sections/upload/displayRecords.jsx +++ b/client/src/sections/upload/displayRecords.jsx @@ -5,12 +5,11 @@ import axios from 'axios'; import IconButton from '@mui/material/IconButton'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import ExpandLessIcon from '@mui/icons-material/ExpandLess'; - +import { axiosInstance } from '../../utils/axiosInstance'; const AdditionalContent = ({ ContentInfo }) => { let comp =

{ContentInfo.url}

; let urlParts = String(ContentInfo.url).replace(/\\/g, '/').split('/'); let url = `http://localhost:3000/upload/patient/medicalHistory/` + urlParts[urlParts.length - 1]; - // console.log(url, "*-*-*-*-*-*-*") if (String(ContentInfo.ext) === 'pdf') { comp = ; } else if (['jpg', 'jpeg', 'png'].includes(String(ContentInfo.ext).toLowerCase())) { @@ -72,7 +71,7 @@ const Row = ({ text, ContentInfo }) => { async function generateRows() { const rows = []; - const res = await axios.get('http://localhost:3000/upload/patient/medicalHistory/'); + const res = await axiosInstance.get('upload/patient/medicalHistory/'); const data = res.data.result; console.log(data + "-------") diff --git a/client/src/sections/upload/registrationUpload.jsx b/client/src/sections/upload/registrationUpload.jsx new file mode 100644 index 0000000..75c15a9 --- /dev/null +++ b/client/src/sections/upload/registrationUpload.jsx @@ -0,0 +1,32 @@ +import { useState } from "react"; +import Upload from "./Upload"; +import Label from "src/components/label"; +function RegistrationUpload() { + const [isUploaded, setIsUploaded] = useState([0, 0, 0]); + const url = "/upload/doctor/registration"; + const handleUploadSuccess = (field) => { + let idx = 0; + if (field == 'medicalLicenses') + idx = 1; + else if (field == 'medicalDegree') + idx = 2; + isUploaded[idx] = 1; + setIsUploaded([...isUploaded]); + + }; + const style = { fontSize: '16px' }; + return ( +
+ + + + + + + + + +
+ ); +} +export default RegistrationUpload; \ No newline at end of file diff --git a/client/src/utils/axiosInstance.js b/client/src/utils/axiosInstance.js index 98b04c9..656d369 100644 --- a/client/src/utils/axiosInstance.js +++ b/client/src/utils/axiosInstance.js @@ -1,9 +1,9 @@ import axios from 'axios'; export const axiosInstance = axios.create({ - baseURL: 'http://localhost:3000', - withCredentials: true, - headers: { - 'Content-Type': 'application/json' - } + baseURL: 'http://localhost:3000', + withCredentials: true, + headers: { + 'Content-Type': 'application/json' + } }); \ No newline at end of file diff --git a/client/yarn.lock b/client/yarn.lock index 2e04607..f90fd3e 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -40,7 +40,7 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/runtime@^7.12.5", "@babel/runtime@^7.18.3", "@babel/runtime@^7.20.7", "@babel/runtime@^7.21.0", "@babel/runtime@^7.22.6", "@babel/runtime@^7.23.1", "@babel/runtime@^7.23.2", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.7": +"@babel/runtime@^7.12.5", "@babel/runtime@^7.18.3", "@babel/runtime@^7.20.7", "@babel/runtime@^7.21.0", "@babel/runtime@^7.22.6", "@babel/runtime@^7.23.1", "@babel/runtime@^7.23.2", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.2", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.7": version "7.23.2" resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.2.tgz" integrity sha512-mM8eg4yl5D6i3lu2QKPuPH4FArvJ8KhTofbE7jwMUv9KX5mBvwPAqnV3MlyBNqdp9RyRKP6Yck8TrfYrPvX3bg== @@ -1084,7 +1084,7 @@ batch@0.6.1: resolved "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz" integrity sha512-x+VAiMRL6UPkx+kudNvxTl6hB2XNNCG2r+7wixVfIYwu/2HKRXimwQyaumLjMveWvT2Hkd/cAJw+QBMfJ/EKVw== -big-integer@^1.6.44: +big-integer@^1.6.16, big-integer@^1.6.44: version "1.6.51" resolved "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz" integrity sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg== @@ -1199,6 +1199,20 @@ braces@^3.0.2, braces@~3.0.2: dependencies: fill-range "^7.0.1" +broadcast-channel@^3.4.1: + version "3.7.0" + resolved "https://registry.npmjs.org/broadcast-channel/-/broadcast-channel-3.7.0.tgz" + integrity sha512-cIAKJXAxGJceNZGTZSBzMxzyOn72cVgPnKx4dc6LRjQgbaJUQqhy5rzL3zbMxkMWsGKkv2hSFkPRMEXfoMZ2Mg== + dependencies: + "@babel/runtime" "^7.7.2" + detect-node "^2.1.0" + js-sha3 "0.8.0" + microseconds "0.2.0" + nano-time "1.0.0" + oblivious-set "1.0.0" + rimraf "3.0.2" + unload "2.2.0" + brorand@^1.0.1, brorand@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz" @@ -2014,7 +2028,7 @@ detect-libc@^2.0.0: resolved "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz" integrity sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw== -detect-node@^2.0.4: +detect-node@^2.0.4, detect-node@^2.1.0: version "2.1.0" resolved "https://registry.npmjs.org/detect-node/-/detect-node-2.1.0.tgz" integrity sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g== @@ -3928,6 +3942,11 @@ iterator.prototype@^1.1.2: reflect.getprototypeof "^1.0.4" set-function-name "^2.0.1" +js-sha3@0.8.0: + version "0.8.0" + resolved "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz" + integrity sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q== + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz" @@ -4220,6 +4239,14 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" +match-sorter@^6.0.2: + version "6.3.1" + resolved "https://registry.npmjs.org/match-sorter/-/match-sorter-6.3.1.tgz" + integrity sha512-mxybbo3pPNuA+ZuCUhm5bwNkXrJTbsk5VWbR5wiwz/GC6LIiegBGn2w3O08UG/jdbYLinw51fSQ5xNU1U3MgBw== + dependencies: + "@babel/runtime" "^7.12.5" + remove-accents "0.4.2" + md5.js@^1.3.4: version "1.3.5" resolved "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz" @@ -4330,6 +4357,11 @@ micromatch@^4.0.4: braces "^3.0.2" picomatch "^2.3.1" +microseconds@0.2.0: + version "0.2.0" + resolved "https://registry.npmjs.org/microseconds/-/microseconds-0.2.0.tgz" + integrity sha512-n7DHHMjR1avBbSpsTBj6fmMGh2AGrifVV4e+WYc3Q9lO+xnSZ3NyhcBND3vzzatt05LFhoKFRxrIyklmLlUtyA== + miller-rabin@^4.0.0: version "4.0.1" resolved "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz" @@ -4498,6 +4530,13 @@ nan@^2.17.0: resolved "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz" integrity sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w== +nano-time@1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/nano-time/-/nano-time-1.0.0.tgz" + integrity sha512-flnngywOoQ0lLQOTRNexn2gGSNuM9bKj9RZAWSzhQ+UJYaAFG9bac4DW9VHjUAzrOaIcajHybCTHe/bkvozQqA== + dependencies: + big-integer "^1.6.16" + nanoid@^3.3.6: version "3.3.6" resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz" @@ -4777,6 +4816,11 @@ object.values@^1.1.6: define-properties "^1.1.4" es-abstract "^1.20.4" +oblivious-set@1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/oblivious-set/-/oblivious-set-1.0.0.tgz" + integrity sha512-z+pI07qxo4c2CulUHCDf9lcqDlMSo72N/4rLUpRXf6fu+q8vjt8y0xS+Tlf8NTJDdTXHbdeO1n3MlbctwEoXZw== + obuf@^1.0.0, obuf@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz" @@ -5354,10 +5398,10 @@ react-helmet-async@^1.3.0: react-fast-compare "^3.2.0" shallowequal "^1.1.0" -react-hook-form@^7.47.0: - version "7.47.0" - resolved "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.47.0.tgz" - integrity sha512-F/TroLjTICipmHeFlMrLtNLceO2xr1jU3CyiNla5zdwsGUGu2UOxxR4UyJgLlhMwLW/Wzp4cpJ7CPfgJIeKdSg== +react-hook-form@^7.48.2: + version "7.48.2" + resolved "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.48.2.tgz" + integrity sha512-H0T2InFQb1hX7qKtDIZmvpU1Xfn/bdahWBN1fH19gSe4bBEqTfmlr7H3XWTaVtiK4/tpPaI1F3355GPMZYge+A== react-is@^16.13.1: version "16.13.1" @@ -5385,6 +5429,15 @@ react-pdf-viewer@^0.1.0: webpack "^3.10.0" webpack-dev-server "^2.9.7" +react-query@^3.39.3: + version "3.39.3" + resolved "https://registry.npmjs.org/react-query/-/react-query-3.39.3.tgz" + integrity sha512-nLfLz7GiohKTJDuT4us4X3h/8unOh+00MLb2yJoGTPjxKs2bc1iDhkNx2bd5MKklXnOD3NrVZ+J2UXujA5In4g== + dependencies: + "@babel/runtime" "^7.5.5" + broadcast-channel "^3.4.1" + match-sorter "^6.0.2" + react-router-dom@^6.16.0: version "6.16.0" resolved "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.16.0.tgz" @@ -5419,7 +5472,7 @@ react@^16.14.0, react@^16.2.0: object-assign "^4.1.1" prop-types "^15.6.2" -"react@^16.6.0 || ^17.0.0 || ^18.0.0", "react@^16.8.0 || ^17 || ^18", "react@^17.0.0 || ^18.0.0", react@^18.2.0, react@>=0.13, react@>=16, react@>=16.6.0, react@>=16.8, react@>=16.8.0: +"react@^16.6.0 || ^17.0.0 || ^18.0.0", "react@^16.8.0 || ^17 || ^18", "react@^16.8.0 || ^17.0.0 || ^18.0.0", "react@^17.0.0 || ^18.0.0", react@^18.2.0, react@>=0.13, react@>=16, react@>=16.6.0, react@>=16.8, react@>=16.8.0: version "18.2.0" resolved "https://registry.npmjs.org/react/-/react-18.2.0.tgz" integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ== @@ -5606,6 +5659,11 @@ regexp.prototype.flags@^1.4.3, regexp.prototype.flags@^1.5.1: define-properties "^1.2.0" set-function-name "^2.0.0" +remove-accents@0.4.2: + version "0.4.2" + resolved "https://registry.npmjs.org/remove-accents/-/remove-accents-0.4.2.tgz" + integrity sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA== + remove-trailing-separator@^1.0.1: version "1.1.0" resolved "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz" @@ -5707,7 +5765,7 @@ rimraf@^2.2.8: dependencies: glob "^7.1.3" -rimraf@^3.0.2: +rimraf@^3.0.2, rimraf@3.0.2: version "3.0.2" resolved "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz" integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== @@ -6761,6 +6819,14 @@ universalify@^2.0.0: resolved "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz" integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== +unload@2.2.0: + version "2.2.0" + resolved "https://registry.npmjs.org/unload/-/unload-2.2.0.tgz" + integrity sha512-B60uB5TNBLtN6/LsgAf3udH9saB5p7gqJwcFfbOEZ8BcBHnGwCf6G/TGiEqkRAxX7zAFIUtzdrXQSdL3Q/wqNA== + dependencies: + "@babel/runtime" "^7.6.2" + detect-node "^2.0.4" + unpipe@~1.0.0, unpipe@1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz" diff --git a/server/src/routes/upload.route.ts b/server/src/routes/upload.route.ts index fa6d90f..bedc899 100644 --- a/server/src/routes/upload.route.ts +++ b/server/src/routes/upload.route.ts @@ -11,23 +11,23 @@ const uploadRouter = Router(); // uploadRouter.use(isAuthenticated); uploadRouter.post("/patient/medicalHistory", medicalHistoryUpload.array("medicalHistory"),(req, res) => { - controller(res)(saveMedicalHistory)("652b367ea1c23056f61e2651",req.files); + controller(res)(saveMedicalHistory)( req.decoded.id,req.files); }); uploadRouter.get("/patient/medicalHistory/:recordName",async (req, res) => { const recordName: string = req.params["recordName"]; - const fileUrl: any = await getMedicalHistoryURL({ recordName, _id: "652b367ea1c23056f61e2651" }); + const fileUrl: any = await getMedicalHistoryURL({ recordName, _id: req.decoded.id }); res.status(200).sendFile(fileUrl!); }) uploadRouter.get("/patient/medicalHistory/",async (req, res) => { - controller(res)(getMedicalHistory)("652b367ea1c23056f61e2651"); + controller(res)(getMedicalHistory)(req.decoded.id); }) uploadRouter.delete("/patient/medicalHistory/:recordName", (req, res) => { - controller(res)(removeMedicalHistory)("652b367ea1c23056f61e2651",req.params.recordName); + controller(res)(removeMedicalHistory)(req.decoded.id,req.params.recordName); }); uploadRouter.post("/doctor/registration", registrationUpload.fields(allowedRegistrationFields as any[]),(req, res) => { - controller(res)(saveRegistrationFiles)("652b367ea1c23056f61e2651", req.files); + controller(res)(saveRegistrationFiles)("652b3a615c37bacab1ef288f", req.files); }); uploadRouter.use((err: any, req: Request, res: Response) => { if (err instanceof multer.MulterError) { diff --git a/server/src/services/doctor.service.ts b/server/src/services/doctor.service.ts index 2d5918b..732763a 100644 --- a/server/src/services/doctor.service.ts +++ b/server/src/services/doctor.service.ts @@ -45,6 +45,8 @@ const getDoctors = async (query: any) => { return { result: doctors, status: StatusCodes.OK }; }; const getPath = (files: any) => { + console.log(files) + let results = []; for (let i = 0; i < files.length; i++) { const idx = files[i].path.indexOf('uploads'); @@ -53,22 +55,32 @@ const getPath = (files: any) => { return results; } -const saveRegistrationFiles = (doctorID: string, files: any) => { +const saveRegistrationFiles = async (doctorID: string, files: any) => { const IDFiles = files.ID; const degreeFiles = files.medicalDegree; const licensesFields = files.medicalLicenses; - let IDPath = getPath(IDFiles)[0]; - let degreePath: any[] = getPath(degreeFiles); - let licensePath: any[] = getPath(licensesFields); - - const results = Request.findOneAndUpdate({ medicID: doctorID }, { + + let IDPath: any = IDFiles ? (getPath(IDFiles)![0]) : undefined; + let degreePath: any[] = degreeFiles ? getPath(degreeFiles) : []; + let licensePath: any[] = licensesFields ? getPath(licensesFields) : []; + // Construct the updates object + let updates: any = { ID: IDPath, $push: { - degree: { $each: degreePath }, - licenses: { $each: licensePath } + degree: { $each: degreePath }, // Use $each for pushing multiple elements + licenses: { $each: licensePath } // Use $each for pushing multiple elements } - }); + }; + + // Remove the 'ID' field if it doesn't exist + if (!IDPath) { + delete updates.ID; + } + console.log(updates, "------------"); + const results = await Request.findOneAndUpdate({ medicID: doctorID }, updates, { new: true }); + // const results = await Request.findOneAndUpdate({ medicID: doctorID }, updates, {new:true}); + console.log(results); return { result: results, status: StatusCodes.OK, @@ -76,7 +88,6 @@ const saveRegistrationFiles = (doctorID: string, files: any) => { } } - const viewAvailableAppointments = async (doctorID: string) => { const doctor = await Doctor.findById(doctorID); if (!doctor) throw new HttpError(StatusCodes.NOT_FOUND, 'Doctor not found');