implement adding new gang, show only homies for selected gang

This commit is contained in:
Bilal
2020-10-08 01:06:51 +03:00
parent 8832ba071b
commit 51d8a369a9
9 changed files with 198 additions and 16 deletions

View File

@@ -10,10 +10,12 @@ import YesNoModal from "../common/YesNoModal";
const Homies = (props) => {
const [homies, setHomies] = useState([]);
const gang = props.gang;
useEffect(() => {
(async() => {
try {
const response = await axios.get(`/api/homies`);
const response = await axios.get(`/api/gangs/${gang.id}/homies`);
if (response.status === 200 && response.data){
setHomies(response.data);
}else{
@@ -27,7 +29,7 @@ const Homies = (props) => {
const deleteHomie = async (id) => {
try {
const response = await axios.delete(`/api/homies/${id}`);
const response = await axios.delete(`/api/gangs/${gang.id}/homies/${id}`);
if (response.status === 200 && response.data){
setHomies(response.data);
M.toast({ html: "See y'a on the other side Homie" });

View File

@@ -41,10 +41,10 @@ const NewHomieForm = (props) => {
}
try{
const response = await axios.post('/api/homies', newHomie);
const response = await axios.post(`/api/gangs/${gang.id}/homies`, newHomie);
if (response.status === 200 && response.data) {
props.newHomiesSetter(response.data);
M.toast({ html: 'Welcome to the hood' });
M.toast({ html: 'Welcome to the Gang' });
clearForm();
}else{
errorToast();
@@ -86,7 +86,7 @@ const NewHomieForm = (props) => {
<br/>
<Button disabled={disableAddButton()} onClick={addNewHomie}>Add to the hood</Button>
<Button disabled={disableAddButton()} onClick={addNewHomie}>Add to the Gang</Button>
</CollapsibleItem>
</Collapsible>