Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style #18

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"baseUrl": "./src",
"checkJs": true,
"jsx": "react"
}
}
4 changes: 2 additions & 2 deletions src/components/Form/FormComponent2.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ FormComponent2.propTypes = {
pricePerHr: PropTypes.string.isRequired,
seating_capacity: PropTypes.number.isRequired,
rental_duration: PropTypes.number.isRequired,
// image: PropTypes.string.isRequired,
image: PropTypes.string.isRequired,
}).isRequired,
schema: PropTypes.shape({
name: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
pricePerHr: PropTypes.string.isRequired,
seating_capacity: PropTypes.number.isRequired,
rental_duration: PropTypes.number.isRequired,
// image: PropTypes.string.isRequired,
image: PropTypes.string.isRequired,
}).isRequired,
onSubmit: PropTypes.func.isRequired,
children: PropTypes.node.isRequired,
Expand Down
8 changes: 4 additions & 4 deletions src/components/Form/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,21 @@ TextAreaInputField.propTypes = {
export const FileInputField = ({
id, label, name, className, ...props
}) => {
const [field, meta, helpers] = useField(name);
const [, meta, helpers] = useField(name);

const handleChange = (event) => {
const file = event.currentTarget.files[0];
helpers.setValue(file);
// console.log('FIle', file);
console.log('FIle', file);
// return file;
};

return (
<FileInputWrapper className={className}>
<InputLabel htmlFor={props.name || props.id}>{label}</InputLabel>
<StyledFileInput
type="file"
{...field}
{...props}
accept="image/*"
onChange={handleChange}
onBlur={() => helpers.setTouched(true)}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/models/car.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const CarSchema = Yup.object().shape({
pricePerHr: Yup.string().required('Price is required'),
seating_capacity: Yup.number().required('State sitting capacity'),
rental_duration: Yup.number().required('State the duration'),
image: Yup.string(),
image: Yup.string().required('Add Image'),
});

export const carInitialValues = {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/LandingPage/Contact/Contact.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

const Contact = () => (
<div className='contact-page-container'>
<div className="contact-page-container">
<p>CaBooky Vehicle Booking Services.</p>
<p>@2023</p>
</div>
Expand Down
33 changes: 26 additions & 7 deletions src/pages/UserDashboard/AddNewCar/AddNewCarForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,32 @@ const AddNewCarForm = () => {
const dispatch = useDispatch();
const navigate = useNavigate();
const status = useSelector((state) => state.cars.status);
const handleSubmit = (values) => {
dispatch(postNewCar(values));
};

if (status === 'succeeded') {
navigate(`${USERS_DASHBOARD}`);
}
const handleSubmit = (values, { setSubmitting }) => {
const data = new FormData();

data.append('car[name]', values.name);
data.append('car[description]', values.description);
data.append('car[pricePerHr]', values.pricePerHr);
data.append('car[seating_capacity]', values.seating_capacity);
data.append('car[rental_duration]', values.rental_duration);

if (values.image) {
data.append('car[image]', values.image);
}

dispatch(postNewCar(data)).then(() => {
setSubmitting(false);
if (status === 'succeeded') {
navigate(`${USERS_DASHBOARD}`);
}
}).catch((error) => {
if (error) {
return error;
}
return setSubmitting(false);
});
};

return (
<FormComponent2
Expand All @@ -32,7 +51,7 @@ const AddNewCarForm = () => {
<TextInputField label="Price/Hour" name="pricePerHr" placeholder="Price of rent/hr" className="add-new-string" id="add-new-car-form-price" />
<TextInputField label="Seating Capacity" name="seating_capacity" placeholder="Seating Capacity of Car" className="add-new-string" id="add-new-car-form-cap" />
<TextInputField label="Minimum Rent Duration" name="rental_duration" placeholder="Minimum Reantal Duration" className="add-new-string" id="add-new-car-form-duration" />
<FileInputField label="Add Image of Car" name="Add Image" className="add-new-string" id="add-new-car-form-image" />
<FileInputField label="Add Image of Car" name="image" className="add-new-string" id="add-new-car-form-image" />
<FormSubmitButton type="submit" className="add-new-car-submit">
Create Car
</FormSubmitButton>
Expand Down
1 change: 0 additions & 1 deletion src/pages/UserDashboard/DashboardHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const DashboardHome = () => {
name={data.name}
shortNote={data.description}
imgSrc={colorWheel}
deletedAt={data.deleted_at}
/>
))}
</CardContainer>
Expand Down
1 change: 1 addition & 0 deletions src/redux/cars/carsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const carsSlice = createSlice({
.addCase(postNewCar.fulfilled, (state, action) => {
state.status = 'succeeded';
state.cars = [...state.cars, action.payload];
console.log('Car state :', state.cars);
})
.addCase(postNewCar.rejected, (state, action) => {
state.status = 'failed';
Expand Down
1 change: 1 addition & 0 deletions src/redux/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const postNewCar = createAsyncThunk(
Authorization: token,
},
});
console.log('Car Response', response);
return response.data;
} catch (error) {
return thunkAPI.rejectWithValue(error);
Expand Down