Skip to content

Commit

Permalink
Add process.env.API
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobrunodev committed Oct 1, 2019
1 parent 9da687e commit efe3c4a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/containers/DetailsService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import {
WrapperWeekly
} from './styles'

import cafe from '../../img/cafe.jpg'

const DetailsService = ({ id }) => {
const [service, setService] = useState({
address: 'carregando...',
Expand Down Expand Up @@ -114,6 +112,7 @@ const DetailsService = ({ id }) => {
})

const { title, description, week, site, address, district, photo } = service
const { API } = process.env

const printDay = day => {
try {
Expand All @@ -127,7 +126,9 @@ const DetailsService = ({ id }) => {

useEffect(() => {
async function getService() {
const res = await axios.get(`http://localhost:5000/business/${id}`)
const res = await axios.get(
`${API || 'http://localhost:5000'}/business/${id}`
)
setService(res.data)
}

Expand Down
9 changes: 7 additions & 2 deletions src/containers/MainMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const MainMenu = ({ active, closeMenu, openMenu, updateBusiness }) => {
const [categories, setCategories] = useState([])

useEffect(() => {
const { API } = process.env
const featchData = async () => {
const res = await axios.get('http://localhost:5000/category')
const res = await axios.get(`${API || 'http://localhost:5000'}/category`)
console.log('URL', `${API || 'http://localhost:5000'}/category`)
console.log('category', res.data)

setCategories(() => res.data)
}
Expand All @@ -19,13 +22,15 @@ const MainMenu = ({ active, closeMenu, openMenu, updateBusiness }) => {
}, [])

useEffect(() => {
const { API } = process.env

const getServicesByActiveCategories = async () => {
const activeCategories = categories
.filter(category => category.active)
.map(category => category.content)

const { data } = await axios.get(
`http://localhost:5000/business/categories`,
`${API || 'http://localhost:5000'}/business/categories`,
{
params: {
categories: activeCategories
Expand Down
12 changes: 8 additions & 4 deletions src/containers/ServiceForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ const ServiceForm = () => {
})
const [categories, setCategories] = useState([])
const [photo, setPhoto] = useState()
const { API } = process.env

const send = async () => {
const {
data: { location }
} = await axios.post('http://localhost:5000/business/photo', photo)
await axios.post('http://localhost:5000/business', {
} = await axios.post(
`${API || 'http://localhost:5000'}/business/photo`,
photo
)
await axios.post(`${API || 'http://localhost:5000'}/business`, {
...service,
photo: location
})
Expand Down Expand Up @@ -70,12 +74,12 @@ const ServiceForm = () => {

useEffect(() => {
async function getAllCategories() {
const res = await axios.get('http://localhost:5000/category')
const res = await axios.get(`${API || 'http://localhost:5000'}/category`)
setCategories(res.data)
}

getAllCategories()
}, [])
}, [API])

return (
<WrapperCard>
Expand Down

0 comments on commit efe3c4a

Please sign in to comment.