Commit 3d9bf45a authored by Vincent Seyller's avatar Vincent Seyller
Browse files

Finitions

parent 4525c5ea
......@@ -11,6 +11,10 @@ let AchievedServices = () => {
const queryCache = useQueryCache();
const history = useHistory();
useEffect(() => {
queryCache.invalidateQueries('AchievedServicesDone');
}, [])
let id = parseInt(useParams().id);
let fetchAchievedServicesDone = async () => {
......@@ -40,42 +44,28 @@ let AchievedServices = () => {
}
let AchievedService = ({achievedService}) => {
let [users, setUsers] = useState(null);
// let [beneficiaries, setBeneficiaries] = useState([]);
let id = parseInt(useParams().id);
let getBeneficiaries = async () => {
return await API.getBeneficiaries({id: id, idService: achievedService.id});
}
// useEffect(() => {
// API.getBeneficiaries({id: id, idService: achievedService.id})
// .then(data => setBeneficiaries(data));
// }, []);
return <>
<Typography variant="h6" color="primary">{achievedService.service.title}</Typography>
<Typography variant="overline" color="primary">From {achievedService.from.email}</Typography><br/>
<Typography variant="overline" color="primary">For</Typography>
<ul>
<li>
t
</li>
<li>
t
</li>
</ul>
<br/>
{/* {requestedService.validating ?
<Typography variant="overline" color="primary">To validate</Typography> :
<>{requestedService.adding ?
<Typography variant="overline">To add</Typography> :
<Typography variant="overline" color="error">To delete</Typography>
}</>}
<br/>
<Typography>{requestedService.service.description}</Typography>
<Typography variant="overline" color="primary">For some people</Typography>
<Typography color="primary">{achievedService.service.description}</Typography>
<Typography variant="overline" color="primary"><h4>{achievedService.service.cost}</h4></Typography>
<Typography>{achievedService.date}</Typography>
{/* <ul>
{beneficiaries && beneficiaries.map((beneficiarie, idx) => {
return <li key={idx}>{beneficiarie.email}</li>;
})}
</ul> */}
<br/>
{vote != null ?
vote ?
<p>Already voted</p> :
// <><Button variant="success" onClick={() => voteForRequestedService(true)}>Add</Button> <Button variant="danger" onClick={() => voteForRequestedService(false)}>Decline</Button></>
<p>Vote here !</p> :
null */}
</>
}
......
......@@ -2,7 +2,7 @@ import {useQuery, useMutation, useQueryCache} from 'react-query';
import {useParams, useHistory} from 'react-router-dom';
import {ListGroup, Button, Container} from 'react-bootstrap';
import {TextField, Typography} from '@material-ui/core/'
import {useState} from 'react';
import {useState, useEffect} from 'react';
import API from './API';
......@@ -10,6 +10,10 @@ let Details = () => {
const queryCache = useQueryCache();
useEffect(() => {
queryCache.invalidateQueries('Members');
}, [])
let user = JSON.parse(window.localStorage.getItem('user'));
let id = parseInt(useParams().id);
......@@ -29,7 +33,7 @@ let Details = () => {
};
let createService = service => {
return API.createService({id: id, tilte: service.title, description: service.description, cost: service.cost});
return API.createService({id: id, title: service.title, description: service.description, cost: service.cost});
};
let AddMemberForm = () => {
......@@ -45,6 +49,7 @@ let Details = () => {
}
},
onSuccess: (data) => {
setEmail('');
queryCache.invalidateQueries('Members')
}
});
......@@ -66,7 +71,10 @@ let Details = () => {
let [cost, setCost] = useState(null);
const [mutationCreate] = useMutation(createService, {
onSuccess: (data) => {
queryCache.invalidateQueries('Services')
queryCache.invalidateQueries('Services');
setTitle('');
setDescription('');
setCost('');
}
});
const handleSubmit = event => {
......@@ -95,15 +103,29 @@ let Details = () => {
<>
<h1>{data[0].colocation.name}</h1>
<br/>
<Button variant='primary' style={{'marginRight':"5px"}} onClick={() => history.push('/colocation/' + id + '/achievedServices')}>
Services done
</Button>
<Button disabled variant='primary' style={{'marginRight':"5px"}} onClick={() => history.push('/colocation/' + id + '/services')}>
Services to vote
</Button>
<Button variant='primary' style={{'marginRight':"5px"}} onClick={() => history.push('/colocation/' + id + '/services')}>
Services up
</Button>
<Button variant='primary' style={{'marginRight':"5px"}} onClick={() => history.push('/colocation/' + id + '/messages')}>
Messages
</Button>
<br/>
<br/>
<h2>Members</h2>
<ListGroup>
{data.map((member, idx) => {
return <ListGroup.Item key={idx}>
<Typography variant="h6" color="primary">{member.user.email}</Typography>
<Typography color="primary">{member.user.firstName} {member.user.lastName}</Typography>
{member.sold < 0 ?
{member.sold == 0 ?
<Typography color="error">Sold : {member.sold}</Typography> :
<Typography color="primary">Sold : {member.sold}</Typography>
<Typography style={{color:'green'}}>Sold : {member.sold}</Typography>
}
</ListGroup.Item>
})}
......@@ -113,15 +135,6 @@ let Details = () => {
<Typography color="error"><br/>{errorMember}</Typography>
<AddServiceForm />
<br/>
<Button variant='primary' style={{'marginRight':"5px"}} onClick={() => history.push('/colocation/' + id + '/services')}>
Services history
</Button>
<Button variant='primary' style={{'marginRight':"5px"}} onClick={() => history.push('/colocation/' + id + '/requestedServices')}>
Requested Services
</Button>
<Button variant='primary' style={{'marginRight':"5px"}} onClick={() => history.push('/colocation/' + id + '/messages')}>
Messages
</Button>
</>
)}
</Container>;
......
......@@ -13,11 +13,11 @@ let RequestedServices = () => {
let id = parseInt(useParams().id);
let fetchServices = async () => {
let fetchRequestedServices = async () => {
return await API.fetchServices({id: id});
};
const {data, status} = useQuery('RequestedServices', fetchServices);
const {data, status} = useQuery('RequestedServices', fetchRequestedServices);
return <Container>
<br/>
......@@ -28,8 +28,8 @@ let RequestedServices = () => {
{status === 'success' && (
<>
<ListGroup>
{data.map((requestedService, idx) => {
return <ListGroup.Item key={idx}><RequestedService requestedService={requestedService} /></ListGroup.Item>
{data.map((service, idx) => {
return <ListGroup.Item key={idx}><Service service={service} /></ListGroup.Item>
})}
</ListGroup>
</>
......@@ -39,14 +39,14 @@ let RequestedServices = () => {
</Container>;
}
let RequestedService = ({requestedService}) => {
let RequestedService = ({service}) => {
let [vote, setVote] = useState(null);
let id = parseInt(useParams().id);
useEffect(() => {
API.alreadyVoted({idColoc: id, idService: requestedService.id})
.then(data => setVote(data));
}, [id, requestedService.id]);
}, [id, service.id]);
return <>
<Typography variant="h6" color="primary">{requestedService.service.title}</Typography>
......
import {useQuery, useQueryCache} from 'react-query';
import {useParams, useHistory} from 'react-router-dom';
import {ListGroup, Container, Button} from 'react-bootstrap';
import {Typography} from '@material-ui/core/'
import {useEffect, useState} from 'react';
import API from './API';
let Services = () => {
const queryCache = useQueryCache();
const history = useHistory();
useEffect(() => {
queryCache.invalidateQueries('Services');
}, [])
let id = parseInt(useParams().id);
let fetchServices = async () => {
return await API.fetchServices({id: id});
};
const {data, status} = useQuery('Services', fetchServices);
return <Container>
<br/>
<h2>Services</h2>
<br/>
{status === 'loading' && (<div>Loading data...</div>)}
{status === 'error' && (<div>Error fetching data</div>)}
{status === 'success' && (
<>
<ListGroup>
{data.map((service, idx) => {
return <ListGroup.Item key={idx}><Service service={service} /></ListGroup.Item>
})}
</ListGroup>
</>
)}
<br/>
<Button variant='primary' style={{position:'absolute', top:'100px', right:'100px'}} onClick={() => history.push('/colocation/' + id)}>Back to colocation</Button>
</Container>;
}
let Service = ({service}) => {
return <>
<Typography variant="h6" color="primary">{service.title}</Typography>
<Typography variant="overline" color="primary">Asked by {service.askedBy.email}</Typography><br/>
<Typography color="primary">{service.description}</Typography>
<Typography variant="overline" color="primary"><h4>{service.cost}</h4></Typography>
</>
}
export default Services;
......@@ -15,11 +15,12 @@ import Signin from './Signin'
import Signup from './Signup'
import Colocations from './Colocation'
import Details from './Details'
import Services from './AchievedServices'
import RequestedServices from './RequestedServices'
import AchievedServices from './AchievedServices'
import Services from './Services'
import API from './API'
import Edit from './Edit'
import Messages from './Messages'
import RequestedServices from './RequestedServices';
let useStyles = makeStyles((theme) => ({
root: {
......@@ -127,6 +128,9 @@ let ShareLoc = () => {
<Route path='/edit'>
<Edit edit={edit}/>
</Route>
<Route path='/colocation/:id/achievedServices'>
<AchievedServices />
</Route>
<Route path='/colocation/:id/services'>
<Services />
</Route>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment