diff --git a/.gitignore b/.gitignore index 19862e3..c874565 100644 --- a/.gitignore +++ b/.gitignore @@ -16,10 +16,11 @@ dist-ssr .vscode/* !.vscode/extensions.json .idea -.env .DS_Store *.suo *.ntvs* *.njsproj *.sln *.sw? +.env +/src/Back_end/.env diff --git a/src/.env b/src/.env deleted file mode 100644 index 9af12f5..0000000 --- a/src/.env +++ /dev/null @@ -1,2 +0,0 @@ -VITE_SUPABASE_URL=https://kibzydwyaosjaslultsq.supabase.co -VITE_SUPABASE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtpYnp5ZHd5YW9zamFzbHVsdHNxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTYyMzUzMDMsImV4cCI6MjAzMTgxMTMwM30.7E9_y1Jw-HuahCCVLP_WT3u-0AUHLjCV7_xNNyoTWsk \ No newline at end of file diff --git a/src/Back_end/Routes/apiroutes.js b/src/Back_end/Routes/apiroutes.js new file mode 100644 index 0000000..65d83e7 --- /dev/null +++ b/src/Back_end/Routes/apiroutes.js @@ -0,0 +1,17 @@ +const express = require('express'); +const router = express.Router(); +const { sendUserEmail } = require("../utils/sendUsermail"); + +router.post('/sendUserEmail', async (req, res) => { + try { + const { to,subject, message } = req.body; + await sendUserEmail(to,subject, message); // Call your backend function to send email + + res.status(200).send('Email sent successfully'); + } catch (error) { + console.error('Error sending email:', error); + res.status(500).send('Failed to send email'); + } +}); + +module.exports = router; diff --git a/src/Back_end/package-lock.json b/src/Back_end/package-lock.json new file mode 100644 index 0000000..d287007 --- /dev/null +++ b/src/Back_end/package-lock.json @@ -0,0 +1,804 @@ +{ + "name": "back_end", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "back_end", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^16.4.5", + "express": "^4.19.2", + "nodemailer": "^6.9.14" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/body-parser": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", + "license": "MIT", + "dependencies": { + "bytes": "3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "on-finished": "2.4.1", + "qs": "6.11.0", + "raw-body": "2.5.2", + "type-is": "~1.6.18", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", + "license": "MIT" + }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "license": "MIT", + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz", + "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "1.20.2", + "content-disposition": "0.5.4", + "content-type": "~1.0.4", + "cookie": "0.6.0", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "1.2.0", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.7", + "qs": "6.11.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "0.18.0", + "serve-static": "1.15.0", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + } + }, + "node_modules/finalhandler": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", + "integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "2.4.1", + "parseurl": "~1.3.3", + "statuses": "2.0.1", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "license": "MIT", + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "license": "MIT", + "dependencies": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==", + "license": "MIT" + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/nodemailer": { + "version": "6.9.14", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.14.tgz", + "integrity": "sha512-Dobp/ebDKBvz91sbtRKhcznLThrKxKt97GI2FAlAyy+fk19j73Uz3sBXolVtmcXjaorivqsbbbjDY+Jkt4/bQA==", + "license": "MIT-0", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", + "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==", + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", + "license": "MIT", + "dependencies": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", + "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "2.4.1", + "range-parser": "~1.2.1", + "statuses": "2.0.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/serve-static": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", + "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", + "license": "MIT", + "dependencies": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "0.18.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "license": "MIT", + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", + "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "license": "MIT", + "dependencies": { + "call-bind": "^1.0.7", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + } + } +} diff --git a/src/Back_end/package.json b/src/Back_end/package.json new file mode 100644 index 0000000..f96ff15 --- /dev/null +++ b/src/Back_end/package.json @@ -0,0 +1,19 @@ +{ + "name": "back_end", + "version": "1.0.0", + "main": "server.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^16.4.5", + "express": "^4.19.2", + "nodemailer": "^6.9.14" + } +} diff --git a/src/Back_end/server.js b/src/Back_end/server.js new file mode 100644 index 0000000..a049505 --- /dev/null +++ b/src/Back_end/server.js @@ -0,0 +1,21 @@ +// app.js +const express = require("express"); +const cors = require("cors"); +const apiRouter = require("./Routes/apiroutes"); +require("dotenv").config(); + +const app = express(); +const port = process.env.Port; +console.log(port); + +// Middleware to parse JSON bodies and enable CORS +app.use(express.json()); +app.use(cors()); + +// Use routes defined in apiRouter +app.use("/api", apiRouter); + +// Start the Express server +app.listen(port, () => { + console.log(`Server is running at http://localhost:${port}`); +}); diff --git a/src/Back_end/utils/sendUsermail.js b/src/Back_end/utils/sendUsermail.js new file mode 100644 index 0000000..2a33153 --- /dev/null +++ b/src/Back_end/utils/sendUsermail.js @@ -0,0 +1,30 @@ +const nodemailer = require("nodemailer"); +require("dotenv").config(); + +const mail = process.env.EMAIL_USER; +const password = process.env.EMAIL_PASS; + +async function sendUserEmail(to, subject, text) { + try { + let transporter = nodemailer.createTransport({ + service: "gmail", + auth: { + user: mail, + pass: password, + }, + }); + + let info = await transporter.sendMail({ + from: mail, + to: to, + subject: subject, + text: text, + }); + + console.log("Message sent: %s", info.messageId); + } catch (error) { + console.error("Error sending email:", error); + throw error; // Propagate the error up if needed + } +} +module.exports = { sendUserEmail }; diff --git a/src/Front_end/Mailing/mailsender.jsx b/src/Front_end/Mailing/mailsender.jsx new file mode 100644 index 0000000..0640b2c --- /dev/null +++ b/src/Front_end/Mailing/mailsender.jsx @@ -0,0 +1,135 @@ +import { useContext, useEffect, useState } from "react"; +import { Allconvers } from "../context api/context"; +import { + fetchusertodo, + mailtimestampupd, + fetchmailsentmsg, + fetchmailbool, +} from "../database"; +import supabase from "../supabase"; + +const TodoListChanges = () => { + const { currentUser } = useContext(Allconvers); + const [todoList, setTodoList] = useState([]); + const [refresh, setRefresh] = useState(false); + + + useEffect(() => { + const fetching = async () => { + const fetched = await fetchusertodo(currentUser[0]?.id); + setTodoList(fetched); + console.log("Todo list refreshed"); + setRefresh(false); + }; + fetching(); + }, [currentUser[0], refresh]); + + useEffect(() => { + const checking = async () => { + await checkAndSendUserEmail(todoList); + console.log(todoList); + }; + checking(); + }, [todoList]); + + const checkAndSendUserEmail = async (tasks) => { + try { + const now = new Date(); + + for (const task of tasks) { + if (task?.duedate) { + const dueDate = new Date(task.duedate); + const timeDifference = dueDate.getTime() - now.getTime(); // Difference in milliseconds + const minutesDifference = Math.floor(timeDifference / (1000 * 60)); // Convert to minutes + + const thresholds = [ + { threshold: 24 * 60, message: "1 day" }, + { threshold: 12 * 60, message: "12 hours" }, + { threshold: 60, message: "1 hour" }, + { threshold: 30, message: "30 minutes" }, + ]; + + thresholds.sort((a, b) => a.threshold - b.threshold); + + // Fetch already sent messages for this task + const thresholds_sent = await fetchmailsentmsg(task.task_id); + const mailbool = await fetchmailbool(task.task_id); + console.log(mailbool); + // Flag to check if an email has been sent + let emailSent = false; + + for (const { threshold, message } of thresholds) { + if (minutesDifference <= threshold && minutesDifference > 0) { + // Send email only if this threshold hasn't been sent for this task + if ( + !thresholds_sent?.includes(message) && + !emailSent && + !mailbool + ) { + const response = await fetch( + `http://localhost:${ + import.meta.env.VITE_Backend_Port + }/api/sendUserEmail`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + to: currentUser[0].email, + subject: `Task Due Soon (${message} left)`, + message: `Task "${task.taskname}" is due soon. Due Date: ${task.duedate}`, + }), + } + ); + + if (response.ok) { + // Record the sent threshold for this task in the database + await mailtimestampupd(task.task_id, message); + console.log(`Email sent successfully for ${message}`); + emailSent = true; // Set flag to true after sending email so that only 1 mail be sent + } else { + throw new Error(`Failed to send email for ${message}`); + } + } + } + } + } + } + } catch (error) { + console.error("Error checking and sending emails:", error); + } + }; + + useEffect(() => { + const userlistupd = () => { + const userlistupds = supabase + .channel("user_task_list") + .on( + "postgres_changes", + { + event: "*", + schema: "public", + table: "Todo_list", + select: "todo_list", + filter: `id=eq.${currentUser[0]?.id}`, + }, + (payload) => { + setRefresh(true); + console.log("Received todo list changes"); + } + ) + .subscribe(); + + // Cleanup function to unsubscribe from the channel to avoid data leakage + return () => { + supabase.removeChannel(userlistupds); + }; + }; + + userlistupd(); + }, [currentUser[0]?.id]); + return <> +}; + +export default TodoListChanges; diff --git a/src/Front_end/context api/context.jsx b/src/Front_end/context api/context.jsx index 5b0682f..c7bad55 100644 --- a/src/Front_end/context api/context.jsx +++ b/src/Front_end/context api/context.jsx @@ -31,6 +31,7 @@ export const AllconversProvider = ({ children }) => { if (user && user.length > 0) { console.log("Fetched User ID:", user[0].id); setCurrentUser(user); + } } catch (error) { console.error("Error fetching user data:", error); diff --git a/src/Front_end/database.jsx b/src/Front_end/database.jsx index 26eaa9f..bbb0071 100644 --- a/src/Front_end/database.jsx +++ b/src/Front_end/database.jsx @@ -360,3 +360,78 @@ export async function fetchchanneltodo(id) { console.log(error); } } +export async function insert_taskid(id) { + try { + const { data, error } = await supabase + .from("Mails_sent") + .insert([{ task_id: id }]) + .select(); + if (data) { + console.log("done task id insert "); + return true; + } else { + //insert new row with a new users uuid into tos_list where all dm contacts data be stored + console.log("task id insert ", error); + return false; + } + } catch (error) { + console.log(error); + return false; + } +} +export async function mailtimestampupd(id, timestamp) { + try { + const { data: updatedtimestamp, error } = await supabase + .from("Mails_sent") + .update({ last_sent: timestamp, t_f: true }) + .eq("task_id", id) + .select(); + if (updatedtimestamp) { + console.log("done update of timestamp"); + return true; + } else { + //insert new row with a new users uuid into timestamps_list where all dm contacts data be stored + console.log("update timestamp", error); + return false; + } + } catch (error) { + console.log(error); + return false; + } +} +export async function fetchmailsentmsg(id) { + try { + const { data: mail_lastsent, error } = await supabase + .from("Mails_sent") + .select("last_sent") + .eq("task_id", id); + if (error) { + console.log("error fething last_sent todo", error); + } else { + console.log("recieved last_sent todo"); + return mail_lastsent; + } + } catch (error) { + console.log(error); + } +} +export async function fetchmailbool(id) { + try { + const { data: mail_bool, error } = await supabase + .from("Mails_sent") + .select("t_f") + .eq("task_id", id); + if (error) { + console.log("error fething t_f todo", error); + } else { + console.log("recieved t_f todo"); + if (mail_bool[0].t_f == null) { + return false; + } else { + return mail_bool[0].t_f; + } + } + } catch (error) { + console.log(error); + } +} diff --git a/src/Front_end/homepage/ToDo_list/assigntask.jsx b/src/Front_end/homepage/ToDo_list/assigntask.jsx index 2ecfdcc..0ada61c 100644 --- a/src/Front_end/homepage/ToDo_list/assigntask.jsx +++ b/src/Front_end/homepage/ToDo_list/assigntask.jsx @@ -9,6 +9,7 @@ import { Getuserdetails, fetchchanneltodo, fetchusertodo, + insert_taskid, } from "../../database.jsx"; // Import your utility functions import { v4 as uuid } from "uuid"; @@ -18,7 +19,7 @@ const Assigntask = () => { const [assignToMember, setAssignToMember] = useState(true); const [selectedMemberId, setSelectedMemberId] = useState(null); // State to store selected member ID const [searchQuery, setSearchQuery] = useState(""); - const [searchResults, setSearchResults] = useState([]); + const [selectedMembermail, setSelectedMembermail] = useState(null); const [taskName, setTaskName] = useState(""); const [dueDateTime, setDueDateTime] = useState(""); const [noDueDate, setNoDueDate] = useState(false); // State to track if "No Due Date" option is selected @@ -54,11 +55,11 @@ const Assigntask = () => { fetchChannelTodoList(); }, [channel_data, refreshchannellist]); useEffect(() => { - console.log(refreshchannellist), [refreshchannellist]; - }); + console.log(refreshchannellist); + }, [refreshchannellist]); useEffect(() => { - console.log(refreshuserlist), [refreshuserlist]; - }); + console.log(refreshuserlist); + }, [refreshuserlist]); useEffect(() => { const chanlistupd = () => { const channellistupd = supabase @@ -182,6 +183,7 @@ const Assigntask = () => { .from("Channel_todolist") .update({ todo_list: todoListData }) .eq("id", channel_data.channel_id); + await insert_taskid(task_id); } else { todoListData = [ ...user_todo, @@ -201,6 +203,33 @@ const Assigntask = () => { .from("Todo_list") .update({ todo_list: todoListData }) .eq("id", selectedMemberId); + await insert_taskid(task_id); + try { + const response = await fetch( + `http://localhost:${ + import.meta.env.VITE_Backend_Port + }/api/sendUserEmail`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + to: selectedMembermail, + subject: `New Task Assigned`, + message: `Task "${taskName}" was assigned to you by "${ + currentUser[0].username + }". Due Date: ${noDueDate ? null : dueDateTime || null}`, + }), + } + ); + if (!response.ok) { + throw new Error("Failed to send email"); + } + console.log("Email sent successfully"); + } catch (error) { + console.error("Error sending email:", error); + } } // Clear input fields and reset states after successful submission @@ -281,7 +310,10 @@ const Assigntask = () => {
setSelectedMemberId(member[0]?.id)} + onClick={() => { + setSelectedMemberId(member[0]?.id); + setSelectedMembermail(member[0]?.email); + }} > {member ? ( <> diff --git a/src/Front_end/homepage/ToDo_list/mytododlist.jsx b/src/Front_end/homepage/ToDo_list/mytododlist.jsx index f154901..04b4021 100644 --- a/src/Front_end/homepage/ToDo_list/mytododlist.jsx +++ b/src/Front_end/homepage/ToDo_list/mytododlist.jsx @@ -3,7 +3,7 @@ import assigntaskselfCSS from "./mytodolist.module.css"; import { Allconvers } from "../../context api/context"; import { useContext, useState, useEffect } from "react"; import { ImCross } from "react-icons/im"; -import { fetchusertodo } from "../../database.jsx"; // Import your utility functions +import { fetchusertodo,insert_taskid } from "../../database.jsx"; // Import your utility functions import { v4 as uuid } from "uuid"; const Assigntaskself = () => { @@ -92,6 +92,7 @@ const Assigntaskself = () => { .from("Todo_list") .update({ todo_list: todoListData }) .eq("id", currentUser[0].id); + await insert_taskid(task_id) // Clear input fields and reset states after successful submission setTaskName(""); diff --git a/src/Front_end/homepage/channels/addchannelmember.jsx b/src/Front_end/homepage/channels/addchannelmember.jsx index 0a77248..2871a97 100644 --- a/src/Front_end/homepage/channels/addchannelmember.jsx +++ b/src/Front_end/homepage/channels/addchannelmember.jsx @@ -102,6 +102,30 @@ const Addmember = () => { ); if (memupdate) { console.log("mem update successful"); + try { + const response = await fetch( + `http://localhost:${ + import.meta.env.VITE_Backend_Port + }/api/sendUserEmail`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + to: u.email, + subject: `Channel Invitation`, + message: `You are invited to the Channel:"${channel_data.channelname}",by "${currentUser[0].username}"`, + }), + } + ); + if (!response.ok) { + throw new Error("Failed to send email"); + } + console.log("Email sent successfully"); + } catch (error) { + console.error("Error sending email:", error); + } setrefreshchannel(true); } } diff --git a/src/Front_end/homepage/channels/membersofchannel.jsx b/src/Front_end/homepage/channels/membersofchannel.jsx index 461b614..fb464df 100644 --- a/src/Front_end/homepage/channels/membersofchannel.jsx +++ b/src/Front_end/homepage/channels/membersofchannel.jsx @@ -48,6 +48,7 @@ const Showmembers = () => { const [userdm_chats, setuserdm_chats] = useState([]); const [dmcontacts, setDmcontacts] = useState([]); const [dmopenchaclose, setdmopenchaclose] = useState(false); + const [deletesuccess, setdeletesuccess] = useState(false); useEffect(() => { const fetchdmdata = async () => { @@ -274,7 +275,7 @@ const Showmembers = () => { setSelectedMemberId(memberId === selectedMemberId ? null : memberId); }; - const addasadmin = async (memberid) => { + const addasadmin = async (memberid, email) => { try { const allids = await allidsinlist(); for (const Id of allids) { @@ -303,18 +304,44 @@ const Showmembers = () => { } } } + + try { + const response = await fetch( + `http://localhost:${ + import.meta.env.VITE_Backend_Port + }/api/sendUserEmail`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + to: email, + subject: `Made as Admin to a Channel`, + message: `You were made the Admin of the Channel:"${channel_data.channelname}",by "${currentUser[0].username}"`, + }), + } + ); + if (!response.ok) { + throw new Error("Failed to send email"); + } + console.log("Email sent successfully"); + } catch (error) { + console.error("Error sending email:", error); + } } catch (error) { console.error("Error adding admin:", error); } }; - const deleteasadmin = async (memberid) => { + const deleteasadmin = async (memberid, email) => { try { if (memberid === channel_data.channelinfo.createdbyid) { console.log("Cannot delete the creator as admin."); return; } const allids = await allidsinlist(); + for (const Id of allids) { const userChannels = await fetchUserchannelsbyid(Id.id); if (userChannels.length > 0) { @@ -340,15 +367,43 @@ const Showmembers = () => { "Updated userChannels in database:", updatedUserChannels ); + if (updatedUserChannels) { + setdeletesuccess(true); + } } } } + + try { + const response = await fetch( + `http://localhost:${ + import.meta.env.VITE_Backend_Port + }/api/sendUserEmail`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + to: email, + subject: `Removed as Admin to a Channel`, + message: `You were removed as the Admin of the Channel:"${channel_data.channelname}",by "${currentUser[0].username}"`, + }), + } + ); + if (!response.ok) { + throw new Error("Failed to send email"); + } + console.log("Email sent successfully"); + } catch (error) { + console.error("Error sending email:", error); + } } catch (error) { console.error("Error deleting admin:", error); } }; - const Removemember = async (memberid) => { + const Removemember = async (memberid, email) => { try { if (channel_data.channeladmins.some((admin) => admin.id === memberid)) { const allids = await allidsinlist(); @@ -387,6 +442,32 @@ const Showmembers = () => { channel_data.channel_id, updatedmem ); + if (memresult) { + try { + const response = await fetch( + `http://localhost:${ + import.meta.env.VITE_Backend_Port + }/api/sendUserEmail`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + to: email, + subject: `Removed from a Channel`, + message: `You were removed from the Channel:"${channel_data.channelname}",by "${currentUser[0].username}"`, + }), + } + ); + if (!response.ok) { + throw new Error("Failed to send email"); + } + console.log("Email sent successfully"); + } catch (error) { + console.error("Error sending email:", error); + } + } const channelscurrent = await fetchUserchannelsbyid(memberid); console.log(channelscurrent); const updatedchannel = channelscurrent.filter( @@ -620,7 +701,10 @@ const Showmembers = () => {
- addasadmin(member[0].id) + addasadmin( + member[0].id, + member[0].email + ) } >

Add as admin

@@ -628,7 +712,10 @@ const Showmembers = () => {
- Removemember(member[0].id) + Removemember( + member[0].id, + member[0].email + ) } >

Remove

@@ -642,7 +729,10 @@ const Showmembers = () => {
- deleteasadmin(member[0].id) + deleteasadmin( + member[0].id, + member[0].email + ) } >

Delete as admin

@@ -650,7 +740,10 @@ const Showmembers = () => {
- Removemember(member[0].id) + Removemember( + member[0].id, + member[0].email + ) } >

Remove

diff --git a/src/Front_end/homepage/homepage.jsx b/src/Front_end/homepage/homepage.jsx index ad45202..0d502ef 100644 --- a/src/Front_end/homepage/homepage.jsx +++ b/src/Front_end/homepage/homepage.jsx @@ -29,6 +29,8 @@ import { MdAssignmentAdd } from "react-icons/md"; import { FaTasks } from "react-icons/fa"; import Viewutask from "./ToDo_list/viewusertask"; import Assigntaskself from "./ToDo_list/mytododlist"; +import TodoListChanges from "../Mailing/mailsender"; + function Home(data) { const { @@ -228,6 +230,7 @@ function Home(data) { return ( <> + {viewchanneltasks ? : <>} {viewtask ? : <>} {assigntask ? : <>} @@ -238,6 +241,8 @@ function Home(data) { {isLoading ? (

Loading...

// Display loading message while fetching ) : ( + +
@@ -387,7 +392,9 @@ function Home(data) {
+ )} + ); } diff --git a/src/Front_end/supabase.jsx b/src/Front_end/supabase.jsx index 086bf4a..92d21eb 100644 --- a/src/Front_end/supabase.jsx +++ b/src/Front_end/supabase.jsx @@ -1,7 +1,5 @@ import { createClient } from "@supabase/supabase-js"; -const SUPABASE_KEY = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtpYnp5ZHd5YW9zamFzbHVsdHNxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTYyMzUzMDMsImV4cCI6MjAzMTgxMTMwM30.7E9_y1Jw-HuahCCVLP_WT3u-0AUHLjCV7_xNNyoTWsk"; -const supabaseUrl = "https://kibzydwyaosjaslultsq.supabase.co"; -const supabaseKey = SUPABASE_KEY; +const supabaseUrl = import.meta.env.VITE_SUPABASE_URL; +const supabaseKey = import.meta.env.VITE_SUPABASE_KEY; const supabase = createClient(supabaseUrl, supabaseKey); export default supabase;