diff --git a/frontend/app/api/phonebook/[userId]/route.js b/frontend/app/api/phonebook/[userId]/route.js new file mode 100644 index 00000000..55e17659 --- /dev/null +++ b/frontend/app/api/phonebook/[userId]/route.js @@ -0,0 +1,19 @@ +import axios from "axios"; +import { NextResponse } from "next/server"; + +const getUserPhoneBook = async (route) => { + try { + const backendURL = process.env.BACKEND_URL || "http://localhost:5000"; + const userId = (route.url.split('/').reverse()[0]) + console.log(backendURL + "/api/v1/phonebook/user/" + userId) + const {data} = await axios.get(backendURL + "/api/v1/phonebook/user/" + userId); + console.log(data) + return NextResponse.json(data); + } catch (error) { + return NextResponse.error(error); + } +} + +export { + getUserPhoneBook as GET +} \ No newline at end of file diff --git a/frontend/app/api/phonebook/route.js b/frontend/app/api/phonebook/route.js index addd71b5..7c1f86bc 100644 --- a/frontend/app/api/phonebook/route.js +++ b/frontend/app/api/phonebook/route.js @@ -3,8 +3,12 @@ import { NextResponse } from "next/server"; const getAllContacts = async () => { try { - const backendURL = process.env.NEXT_PUBLIC_BACKEND_URL || "http://localhost:5000"; - const {data} = await axios.get(backendURL + "/api/phonebook"); + const backendURL = process.env.BACKEND_URL; + console.log("in") + console.log(backendURL + "/api/v1/phonebook") + const {data} = await axios.get(backendURL + "/api/v1/phonebook"); + console.log(data) + console.log("in") return NextResponse.json(data); } catch (error) { return NextResponse.error(error); @@ -13,9 +17,9 @@ const getAllContacts = async () => { const addContact = async (request) => { try { - const backendURL = process.env.NEXT_PUBLIC_BACKEND_URL || "http://localhost:5000"; + const backendURL = process.env.BACKEND_URL || "http://localhost:5000"; const req = await request.json(); - const {data} = await axios.post(backendURL + "/api/phonebook", req); + const {data} = await axios.post(backendURL + "/api/v1/phonebook", req); return NextResponse.json(data); } catch (error) { return NextResponse.error(error); diff --git a/frontend/app/api/users/route.js b/frontend/app/api/users/route.js new file mode 100644 index 00000000..1767ec48 --- /dev/null +++ b/frontend/app/api/users/route.js @@ -0,0 +1,32 @@ +import axios from "axios"; +import { NextResponse } from "next/server"; + +const login = async (request) => { + try { + const backendURL = process.env.BACKEND_URL || "http://localhost:5000"; + const req = await request.json(); + console.log(backendURL + "/api/v1/users/login") + console.log(req) + const {data} = await axios.post(backendURL + "/api/v1/users/login", req); + console.log(data) + return NextResponse.json(data); + } catch (error) { + return NextResponse.error(error); + } +} + +const register = async (request) => { + try { + const backendURL = process.env.BACKEND_URL || "http://localhost:5000"; + const req = await request.json(); + const {data} = await axios.post(backendURL + "/api/v1/users/", req); + return NextResponse.json(data); + } catch (error) { + return NextResponse.error(error); + } +} + +export { + login as POST, + register as PUT +} \ No newline at end of file diff --git a/frontend/app/login/page.jsx b/frontend/app/login/page.jsx index 5a222fa2..1b5e23cd 100644 --- a/frontend/app/login/page.jsx +++ b/frontend/app/login/page.jsx @@ -15,7 +15,7 @@ const Login = () => { const [ethAddress, setEthAddress] = useState(""); const router = useRouter() const handleLogin = async () => { - const { data } = await axios.post('/api/nest/users/login', { + const { data } = await axios.post('/api/users/', { email, password, ethAddress @@ -23,7 +23,7 @@ const Login = () => { if (data?.ethAddress) { setLogin(true) setUser(data) - router.push('/schedule') + router.push('/schedule-meets') } else { alert("Something went wrong"); } diff --git a/frontend/app/meeting/components/meeting/Controls.jsx b/frontend/app/meeting/components/meeting/Controls.jsx index 30bffa15..af7ce82d 100644 --- a/frontend/app/meeting/components/meeting/Controls.jsx +++ b/frontend/app/meeting/components/meeting/Controls.jsx @@ -19,24 +19,43 @@ const Controls = ({ URL }) => { const { isStarting, inProgress, isStopping, data } = useRecording(); const isMuteOnJoin = useMeetingStore(state => state.isMuteOnJoin); const isDisableVideoOnJoin = useMeetingStore(state => state.isDisableVideoOnJoin); - const recorder = new RecordRTC_Extension(); var screenShareStream = null; + var recorder; + + if (typeof RecordRTC_Extension === 'undefined') { + recorder = null; + } else { + recorder = new RecordRTC_Extension(); + } + const startRecording = async () => { - if (!recorder) { - alert("RecordRTC chrome extension is either disabled or not installed. Install the extension to record the screen") - } else { - recorder.startRecording({ - enableScreen: true, - enableMicrophone: true, - enableSpeakers: true - }); + try { + if (recorder == undefined || recorder == null) { + alert("RecordRTC chrome extension is either disabled or not installed. Install the extension to record the screen") + } else { + recorder.startRecording({ + enableScreen: true, + enableMicrophone: true, + enableSpeakers: true + }); + } + } catch (e) { + console.log(e); } } + const stopRecording = async () => { - recorder.stopRecording(function (blob) { + // console.log(recorder) + recorder.stopRecording(function (blob, error) { console.log("blob", blob) + console.log("error", error) + recorder = null; + if (blob == false) { + alert("RecordRTC chrome extension is either disabled or not installed. Install the extension to record the screen") + return; + } const link = document.createElement('a'); - link.href = window.URL.createObjectURL(blob); + link.href = window.URL?.createObjectURL(blob); link.download = `recording-${+new Date()}.webm`; link.click(); }); diff --git a/frontend/app/phonebook/components/AddContact.jsx b/frontend/app/phonebook/components/AddContact.jsx index 7c45af9b..c1205956 100644 --- a/frontend/app/phonebook/components/AddContact.jsx +++ b/frontend/app/phonebook/components/AddContact.jsx @@ -1,4 +1,3 @@ -import { TextField } from "@mui/material"; import React from "react"; const AddContact = ({addContact, setAddContact, addContactHandler}) => { diff --git a/frontend/app/phonebook/components/GroupsContacts.jsx b/frontend/app/phonebook/components/GroupsContacts.jsx index 930c0817..62164cdf 100644 --- a/frontend/app/phonebook/components/GroupsContacts.jsx +++ b/frontend/app/phonebook/components/GroupsContacts.jsx @@ -1,9 +1,32 @@ -import React from "react"; +"use client"; + +import React, { useEffect } from "react"; import { FiPlusSquare } from "react-icons/fi"; import Image from "next/image"; const GroupsContacts = ({addContact, setAddContact, addGroup, setAddGroup, phonebookData }) => { console.log(phonebookData) + const [filteredData, setFilteredData] = React.useState(phonebookData); + const [search, setSearch] = React.useState(""); + console.log(filteredData) + useEffect(() => { + const data = filterData(); + console.log(data) + setFilteredData(data); + }, [search]); + + useEffect(() => { + if (filteredData.length > 0) return; + setFilteredData(phonebookData); + }, [phonebookData]); + + const filterData = () => { + const newData = phonebookData.filter((contact) => { + return contact.name.toLowerCase().includes(search.toLowerCase()) || contact.address.toLowerCase().includes(search.toLowerCase()); + }); + setFilteredData(newData.length > 0 ? newData : phonebookData); + return newData; + } return (
@@ -36,7 +59,7 @@ const GroupsContacts = ({addContact, setAddContact, addGroup, setAddGroup, phone
Executive - Commitee + Committee
@@ -50,6 +73,10 @@ const GroupsContacts = ({addContact, setAddContact, addGroup, setAddGroup, phone className="border-[2px] border-[#bbbbbb] px-3 rounded-[8px] active:border-[#bbbbbb]" type="text" placeholder=" Search" + onChange={(e) => { + setSearch(e.target.value) + filterData() + }} /> @@ -70,7 +97,7 @@ const GroupsContacts = ({addContact, setAddContact, addGroup, setAddGroup, phone
- {phonebookData + {filteredData ?.map((contact, index) => { if(index%2==1){ @@ -81,7 +108,7 @@ const GroupsContacts = ({addContact, setAddContact, addGroup, setAddGroup, phone
{contact.name}
-
Chairman
+
{contact.address?.substring(0, 6)}...{contact.address?.substring(36,40)}
); } @@ -93,7 +120,7 @@ const GroupsContacts = ({addContact, setAddContact, addGroup, setAddGroup, phone
- {phonebookData + {filteredData ?.map((contact, index) => { if(index%2==0){ return( @@ -103,7 +130,7 @@ const GroupsContacts = ({addContact, setAddContact, addGroup, setAddGroup, phone
{contact.name || contact.email}
-
{contact.ethAddress}
+
{contact.address?.substring(0, 6)}...{contact.address?.substring(36,40)}
); } diff --git a/frontend/app/phonebook/page.jsx b/frontend/app/phonebook/page.jsx index 56380884..1bce722e 100644 --- a/frontend/app/phonebook/page.jsx +++ b/frontend/app/phonebook/page.jsx @@ -6,46 +6,46 @@ import Sidebar from "../schedule-meets/components/Sidebar"; import GroupsContacts from "./components/GroupsContacts"; import AddContact from "./components/AddContact"; import CreateGroup from "./components/CreateGroup"; -import { async } from "regenerator-runtime"; import axios from "axios"; +import { useAppStore } from "../store/AppStore"; +import { useRouter } from "next/navigation"; const Phonebook = () => { const [addGroup, setAddGroup] = React.useState(false); const [addContact, setAddContact] = React.useState(false); - + const router = useRouter(); const [phonebookData, setPhonebookData] = useState([]); + const user = useAppStore(state => state.user) + useEffect(() => { - // fetch("api/phonebook/") - // .then((res) => { - // return res.json(); - // }) - // .then((data) => { - // setPhonebookData(data); - // }); const getData = async () => { - const { data } = await axios.get("/api/nest/users/"); + console.log(user) + if (!user) { + router.push('/login') + } + const { data } = await axios.get("/api/phonebook/" + user.userId); setPhonebookData(data); }; getData(); }, []); console.log(phonebookData) - const addContactHandler = async (name, address, userId) => { + const addContactHandler = async (name, address) => { const response = await axios .post("/api/phonebook/", { name: name, address: address, - userId: 'clmqll67z0001i0887xh2yn8l', + userId: user.userId, }) .then((res) => { - return console.log(res.json()); + console.log(res.json()); + window.location.reload(); }) .catch(function (error) { console.log(`Post req: ${error}`); }); }; - // console.log(phonebookData) return (
@@ -74,7 +74,7 @@ const Phonebook = () => { setAddGroup={setAddGroup} phonebookData={phonebookData} /> - {console.log("Phone" + phonebookData)} + {/* {console.log("Phone" + phonebookData)} */}
); diff --git a/frontend/app/schedule-meets/components/Calendar.jsx b/frontend/app/schedule-meets/components/Calendar.jsx index ebf014aa..86a11c65 100644 --- a/frontend/app/schedule-meets/components/Calendar.jsx +++ b/frontend/app/schedule-meets/components/Calendar.jsx @@ -1,5 +1,5 @@ "use client"; -import React, { useEffect, useState } from "react"; +import React, { use, useEffect, useState } from "react"; import dayjs from "dayjs"; import NextIcon from "@/app/svg-icons/NextIcon"; @@ -11,17 +11,20 @@ import axios from "axios"; import cn from "@/app/utils/cn"; +import { useAppStore } from "@/app/store/AppStore"; const Calendar = () => { const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; const currentDate = dayjs(); const [today, setToday] = useState(currentDate); const [selectDate, setSelectDate] = useState(currentDate); + const user = useAppStore(state => state.user) useEffect(() => { const getMeets = async () => { + console.log(user.ethAddress) const { data } = await axios.patch('/api/meetings', { - "address":"0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc" + "address": user.ethAddress }) console.log(data); } diff --git a/frontend/app/signup/page.jsx b/frontend/app/signup/page.jsx index e162c1cf..c7a491f9 100644 --- a/frontend/app/signup/page.jsx +++ b/frontend/app/signup/page.jsx @@ -6,6 +6,7 @@ import Box from '@mui/material/Box'; import axios from 'axios'; import { useAppStore } from '../store/AppStore'; import { deployContract } from '../hooks/Web3'; +import { useRouter } from 'next/navigation'; const Signup = () => { const [email, setEmail] = React.useState(""); @@ -15,10 +16,11 @@ const Signup = () => { const [confirmPassword, setConfirmPassword] = React.useState(""); const setLogin = useAppStore(state => state.setLogin) const setUser = useAppStore(state => state.setUser) + const router = useRouter() const handleSignup = async () => { const contract = await deployContract('abc def'); console.log(contract.address ?? 'no address') - const { data } = await axios.post('/api/nest/users/', { + const { data } = await axios.put('/api/users/', { email, name: username, ethAddress, @@ -26,10 +28,10 @@ const Signup = () => { password, }); if (data?.ethAddress) { - setLogin(true) setUser(data) alert("Signup successful") + router.push('/login') } else { alert("Something went wrong"); }