Skip to content
This repository was archived by the owner on Aug 8, 2019. It is now read-only.

Commit d36a1a1

Browse files
authored
Merge pull request #11 from codeableorg/feature-ownerhomeui
Feature Owner Home UI
2 parents 6d748b2 + 50d3542 commit d36a1a1

16 files changed

Lines changed: 677 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ client/npm-debug.log*
4848
client/yarn-debug.log*
4949
client/yarn-error.log*
5050

51+
.env
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class ClubsController < ApplicationController
2+
before_action :set_club, only: [:show, :update, :destroy]
3+
4+
def index
5+
render json: Club.all
6+
end
7+
8+
def show
9+
render json: @club
10+
end
11+
12+
rescue_from ActiveRecord::RecordNotFound do |e|
13+
render json: { message: e.message }, status: :not_found
14+
end
15+
16+
private
17+
def set_club
18+
@club = Club.find(params[:id])
19+
end
20+
21+
end

api/config/routes.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
Rails.application.routes.draw do
22
scope '/api' do
3-
# sessions routes
43
post '/login', to: 'sessions#login'
54
post '/register', to: 'sessions#register'
6-
75
delete '/logout', to: 'sessions#destroy'
8-
6+
resources :clubs
7+
resources :sport_fields
98
end
109
end

api/db/seeds.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
User.destroy_all
22
User.create(name: 'Lian Nivin', email: 'liam@kampu.pe', role: "regular", password: '123456')
3-
User.create(name: 'Cristian Berly', email: 'berli@kampu.pe', role: "owner", password: '123456')
3+
User.create(name: 'Cristian Berly', email: 'berli@kampu.pe', role: "owner", password: '123456')
4+
5+
clubs = Club.create([{name: "Club #1"}, {name: "Club #2"}, {name: "Club #3"}])
6+
SportField.create(name: "SportField #1", club_id: 1);
7+
SportField.create(name: "SportField #2", club_id: 2);
8+
SportField.create(name: "SportField #3", club_id: 1);

client/src/actions/action-hooks.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import { useDispatch } from "react-redux";
3+
4+
import { setClubs, setSportFields } from "./actions";
5+
6+
export function useSetClubs() {
7+
const dispatch = useDispatch();
8+
return React.useCallback(clubs => dispatch(setClubs(clubs)), [dispatch]);
9+
}
10+
11+
export function useSetSportFields() {
12+
const dispatch = useDispatch();
13+
return React.useCallback(
14+
sportFields => dispatch(setSportFields(sportFields)),
15+
[dispatch]
16+
);
17+
}

client/src/actions/actions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function setClubs(clubs) {
2+
return { type: "SET_CLUBS", payload: clubs };
3+
}
4+
5+
export function setSportFields(sportFields) {
6+
return { type: "SET_SPORTFIELDS", payload: sportFields };
7+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/** @jsx jsx */
2+
import { jsx } from "@emotion/core";
3+
import { Title } from "../components/ui";
4+
5+
function OwnerClubCircle({ id, active, name, activeClub, setActiveClub }) {
6+
const styleCircle = {
7+
backgroundColor: "#bababa",
8+
width: "80px",
9+
height: "80px",
10+
borderRadius: "50%",
11+
margin: "0 1em",
12+
display: "flex",
13+
cursor: "pointer",
14+
border: "solid #ffffff00 0.5em",
15+
flex: "0 0 80px"
16+
};
17+
18+
const styleActive = {
19+
...styleCircle,
20+
border: "solid #272727 0.5em"
21+
};
22+
23+
const styleName = {
24+
fontWeight: "normal",
25+
margin: "auto",
26+
alignSelf: "center"
27+
};
28+
29+
function handleClick() {
30+
setActiveClub(id);
31+
}
32+
33+
return (
34+
<div
35+
css={activeClub === id ? styleActive : styleCircle}
36+
onClick={handleClick}
37+
>
38+
<Title css={styleName}>{name}</Title>
39+
</div>
40+
);
41+
}
42+
43+
export default OwnerClubCircle;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/** @jsx jsx */
2+
import React from "react";
3+
import { jsx } from "@emotion/core";
4+
5+
function OwnerCreateButton() {
6+
const [active, setActive] = React.useState(false);
7+
8+
const styleButtonContainer = {
9+
position: "fixed",
10+
bottom: "2em",
11+
right: "1em",
12+
background: "#C3C4C3",
13+
width: "3em",
14+
height: "3em",
15+
display: "flex",
16+
justifyContent: "center",
17+
alignItems: "center",
18+
borderRadius: "50%",
19+
20+
transition: "all 0.2s ease"
21+
};
22+
23+
const styleIcon = {
24+
background: "none",
25+
color: "inherit",
26+
border: "none",
27+
padding: "0",
28+
font: "inherit",
29+
cursor: "pointer",
30+
outline: "inherit",
31+
fontSize: "2em",
32+
margin: 0,
33+
transition: "all 0.2s ease"
34+
};
35+
36+
const styleIconActive = {
37+
...styleIcon,
38+
transform: "rotate(45deg)",
39+
position: "absolute",
40+
bottom: "0.5em",
41+
right: "0.5em"
42+
};
43+
44+
const styleListContainer = {
45+
...styleButtonContainer,
46+
width: "12em",
47+
height: "10em",
48+
borderRadius: "15px"
49+
};
50+
51+
const styleButtonsContainer = {
52+
display: "none"
53+
};
54+
55+
const styleButtonsContainerActive = {
56+
...styleButtonsContainer,
57+
display: "block"
58+
};
59+
60+
const styleButton = {
61+
background: "none",
62+
color: "inherit",
63+
border: "none",
64+
padding: "0",
65+
font: "inherit",
66+
cursor: "pointer",
67+
outline: "inherit",
68+
fontSize: "1.3em",
69+
margin: 0,
70+
width: "100%",
71+
"&:hover": {
72+
background: "#a6a6a6"
73+
}
74+
};
75+
76+
function handleClick() {
77+
setActive(!active);
78+
}
79+
80+
return (
81+
<div css={active ? styleListContainer : styleButtonContainer}>
82+
<div css={active ? styleButtonsContainerActive : styleButtonsContainer}>
83+
<button css={styleButton}>Create Club</button>
84+
<button css={styleButton}>Create Sport Field</button>
85+
</div>
86+
<button css={active ? styleIconActive : styleIcon} onClick={handleClick}>
87+
+
88+
</button>
89+
</div>
90+
);
91+
}
92+
93+
export default OwnerCreateButton;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/** @jsx jsx */
2+
import React from "react";
3+
import { jsx } from "@emotion/core";
4+
import { Card, Title, Progress } from "../components/ui";
5+
6+
function OwnerSportFieldCard({ name, progressStatus }) {
7+
const [status, setStatus] = React.useState("0%");
8+
9+
const styleCard = {
10+
maxWidth: "40%",
11+
marginBottom: "1.5em",
12+
"@media screen and (max-width: 530px)": {
13+
maxWidth: "100%"
14+
}
15+
};
16+
17+
React.useEffect(() => {
18+
if (status !== progressStatus) {
19+
setStatus(progressStatus);
20+
}
21+
}, [progressStatus, status]);
22+
23+
return (
24+
<Card css={styleCard}>
25+
<Title>{name}</Title>
26+
<Progress styles={{ bar: { width: status } }} />
27+
<p css={{ textAlign: "center" }}>Bookings: {progressStatus}</p>
28+
</Card>
29+
);
30+
}
31+
32+
export default OwnerSportFieldCard;

0 commit comments

Comments
 (0)