Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Status Feature #146

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ exports.UpdateMe=catchAsync(async(req,res,next)=>{
if(!req.body.name||!req.body.email)
next(new AppError('Empty fields are not allowed',400))

const filteredBody=filterObj(req.body,"name","email")
console.log(req.body);

const filteredBody=filterObj(req.body,"name","email","status")
const updatedUser = await User.findByIdAndUpdate(req.user.id, filteredBody, {
new: true,
runValidators: true
Expand Down
1 change: 1 addition & 0 deletions backend/models/userModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const axios=require('axios')
const userSchema=new mongoose.Schema({
name:{type:String,required:true},
email:{type:String,required:true,unique:true},
status:{type:String,required:false, default:"Available"},
password:{type:String,required:true},
pic: {
type:String,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/SearchComponents/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function User({values,accessChat}) {
<Avatar referrerPolicy="no-referrer" alt="User-pic" sx={{width:48,height:48}} src={values.pic.startsWith('user')?`${process.env.REACT_APP_API_URL}/${values.pic}`:`${values.pic}`} />
<div className='flex flex-col ml-2'>
<div className='font-bold font-Roboto text-sm'>{values.name}</div>
<div className="text-xs text-[#979797]">{values.email}</div>
<div className="text-xs text-[#979797]">{values.status}</div>
</div>
</div>
</MotionAnimate>
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/components/SettingsComponents/InputStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { TextField } from '@mui/material'

export default function InputName({status,setStatus}) {

const nameHandler=(e)=>{
setStatus(e.target.value);
}

return (
<TextField
value={status}
onChange={nameHandler}
id="outlined-read-only-input"
label="Status"
style={{width:'40%'}}
/>
)
}
2 changes: 1 addition & 1 deletion frontend/src/components/SignupComponents/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Main() {

const navigation=useNavigation();
const submit=useSubmit();
const [SignUpData,setSignUpData]=useState({name:'',email:'',password:''});
const [SignUpData,setSignUpData]=useState({name:'',email:'',password:'', status:'Available'});
const[submiting,setSubmiting]=useState(false);
const [showPassword, setShowPassword] = useState(false);

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default function Search() {
}
})
const data=await response.json();
// console.log(data);
SetisLoading(false);
data.users.length=data.users.length>2?data.users.length=2:data.users.length;
SetUsers(data.users)
Expand Down Expand Up @@ -96,3 +97,5 @@ export default function Search() {
</div>
)
}


7 changes: 7 additions & 0 deletions frontend/src/pages/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import Profile from "../components/SettingsComponents/Profile";
import InputName from "../components/SettingsComponents/InputName";
import InputEmail from "../components/SettingsComponents/InputEmail";
import InputStatus from "../components/SettingsComponents/InputStatus";
import { useState,useEffect} from "react";
import {setUser} from '../services/Actions/User/actions'
import { useDispatch } from 'react-redux';
Expand All @@ -14,10 +15,12 @@ export default function Settings() {
const storedData = JSON.parse(localStorage.getItem("info"));
const [name, setName] = useState(storedData.name);
const [email, setEmail] = useState(storedData.email);
const [status, setStatus] = useState(storedData.status);

const resetData = () => {
setName(storedData.name);
setEmail(storedData.email);
setStatus(storedData.status);
};
const notify = (value) => {
if (value === "error")
Expand Down Expand Up @@ -48,7 +51,9 @@ export default function Settings() {
const dataSent = {
name,
email,
status
};
// console.log(dataSent);
const updateData = async () => {
const cookie = localStorage.getItem("jwt");
const response = await fetch(
Expand All @@ -63,6 +68,7 @@ export default function Settings() {
}
);
const data = await response.json();
// console.log(data);
if (data.status === "success")
{
notify("success");
Expand Down Expand Up @@ -91,6 +97,7 @@ export default function Settings() {
<div className="mt-[3%] flex flex-col gap-8">
<InputName name={name} setName={setName}></InputName>
<InputEmail email={email} setEmail={setEmail}></InputEmail>
<InputStatus status={status} setStatus={setStatus}></InputStatus>
</div>
<div className="flex flex-row mt-[2%] gap-2">
<div
Expand Down