generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from flemton/feature/add-cars
Request to merge Feature/add cars to development
- Loading branch information
Showing
9 changed files
with
114 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import Sidebar from '../../components/Sidebar/Sidebar'; | ||
import CarDetails from '../../components/CarDetails/CarDetails'; | ||
import BurgerMenu from '../../components/Menu/BurgerMenu'; | ||
import Session from '../../components/Session/Session'; | ||
|
||
const Home = () => ( | ||
<div className="d-flex justify-content-between align-items-center background-container"> | ||
<div> | ||
<Sidebar /> | ||
<BurgerMenu /> | ||
</div> | ||
const Home = () => { | ||
const user = useSelector((state) => state.login.data); | ||
|
||
return !user?.success ? ( | ||
<Session /> | ||
) : ( | ||
<div className="d-flex justify-content-between align-items-center background-container"> | ||
<div> | ||
<Sidebar /> | ||
<BurgerMenu /> | ||
</div> | ||
|
||
<div className="mx-3"> | ||
<CarDetails /> | ||
<div className="mx-3"> | ||
<CarDetails /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
import apiUrl from '../../misc/apiUrl'; | ||
|
||
const createCar = createAsyncThunk('car/add', async (formData) => { | ||
const teslaData = new FormData(); | ||
teslaData.append('tesla_model[name]', formData.name); | ||
teslaData.append('tesla_model[description]', formData.description); | ||
teslaData.append('tesla_model[deposit]', formData.deposit); | ||
teslaData.append('tesla_model[finance_fee]', formData.finance_fee); | ||
teslaData.append('tesla_model[option_to_purchase_fee]', formData.option_to_purchase_fee); | ||
teslaData.append('tesla_model[total_amount_payable]', formData.total_amount_payable); | ||
teslaData.append('tesla_model[duration]', formData.duration); | ||
teslaData.append('tesla_model[removed]', formData.removed); | ||
teslaData.append('tesla_model[image]', formData.image); | ||
const response = await fetch(`${apiUrl}/tesla_models`, { | ||
method: 'POST', | ||
body: teslaData, | ||
}); | ||
const data = await response.json(); | ||
return data; | ||
}); | ||
|
||
export default createCar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import createCar from '../requests/createCar'; | ||
|
||
const initialState = { | ||
cars: [], | ||
loading: false, | ||
error: null, | ||
}; | ||
|
||
const carSlice = createSlice({ | ||
name: 'car', | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder.addCase(createCar.fulfilled, (state) => ({ | ||
...state, | ||
loading: false, | ||
})); | ||
}, | ||
}); | ||
|
||
export default carSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters