Commit 2dd71225 by jaymehta

table view

1 parent 5ff3e0ee
......@@ -40,4 +40,5 @@ next-env.d.ts
# node
# package.json
package-lock.json
\ No newline at end of file
package-lock.json
yarn.lock
\ No newline at end of file
......@@ -228,7 +228,7 @@ const ActivityDetails = () => {
// enableReinitialize={true}
onSubmit={values => {}}
>
{({ values, errors, touched, handleChange, handleBlur, handleSubmit, setFieldValue }) => (
{({ values, errors, touched, handleChange, handleBlur, handleSubmit, setFieldValue, resetForm }) => (
<Form
onSubmit={async e => {
e.preventDefault();
......@@ -238,16 +238,16 @@ const ActivityDetails = () => {
console.log("sanitizeTimeFormat({ data: item })", sanitizeTimeFormat({ data: item }));
if (!sanitizeTimeFormat({ data: item })) {
console.log("sanitize 1", sanitizeTimeFormat({ data: item }));
toast.error("Time slots can not be empty!")
toast.error("Time slots can not be empty!");
setTimeSlotError(true);
return
return;
}
console.log("sanitize 2", sanitizeTimeFormat({ data: item }));
timeSlots = [...timeSlots, sanitizeTimeFormat({ data: item })];
return sanitizeTimeFormat({ data: item });
});
if (timeSlotError) {
return
return;
}
handleSubmit();
console.log("timeslots", timeSlots);
......@@ -265,11 +265,17 @@ const ActivityDetails = () => {
ageLowerLimit: values.ageGroup,
phoneNumber: values.contactNumberForBooking,
link: values.linkOfBooking,
giftSomeone: values.giftingToSomeone,
giftSomeone: values.giftingToSomeone
};
console.log("values 123", values);
const res = await dispatch(createActivity(values));
console.log("res", res);
if (res.success) {
toast.success("Activity added successfully!");
resetForm();
setActiveDays([]);
setMonths([]);
}
}}
>
<div className="activityDetails">
......
import React, { useEffect, useState } from "react";
import { Table } from "antd";
import { useSelector } from "react-redux";
const onChange = (pagination, filters, sorter, extra) => {
console.log("params", pagination, filters, sorter, extra);
};
export const ActivityListingRBAC = () => {
// let columns = []
// useSelectors
const { allActivitiesData } = useSelector(state => state.allActivitiesData);
const { categories } = useSelector(state => state.categories);
const { subCategories } = useSelector(state => state.subCategories);
// useStates
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
const [columns, setcolumns] = useState([]);
const [data, setdata] = useState([]);
// functions
const onSelectChange = newSelectedRowKeys => {
console.log("selectedRowKeys changed: ", newSelectedRowKeys);
setSelectedRowKeys(newSelectedRowKeys);
};
// useEffects
useEffect(() => {
let initialData = allActivitiesData.data.map((item, index) => {
return {
key: item.id,
name: item.attributes.name,
category: item.attributes.subCategory.data.attributes.category.data.attributes.name,
subCategory: item.attributes.subCategory.data.attributes.name,
location: item.attributes.masterPincode.data.attributes.name,
price: item.attributes.pricePerPerson,
place: item.attributes.activityType,
gift: item.attributes.giftSomeone ? "Yes" : "No"
};
});
const categoryFilterArray = categories.data.map((item, index) => {
return { text: item.attributes.name, value: item.attributes.name };
});
const subCategoryFilterArray = subCategories.data.map((item, index) => {
return { text: item.attributes.name, value: item.attributes.name };
});
setdata(initialData);
setcolumns([
{
title: "Category",
dataIndex: "category",
filters: categoryFilterArray,
filterMode: "tree",
filterSearch: true,
onFilter: (value, record) => record.category.startsWith(value),
width: "15%"
},
{
title: "Sub-category",
dataIndex: "subCategory",
filters: subCategoryFilterArray,
filterSearch: true,
onFilter: (value, record) => record.subCategory.startsWith(value),
width: "15%"
// sorter: (a, b) => a.age - b.age
},
{
title: "Name",
dataIndex: "name",
filters: allActivitiesData.data.map((item) => {
return {text: item.attributes.name, value: item.attributes.name}
}),
onFilter: (value, record) => record.address.startsWith(value),
filterSearch: true,
width: "15%"
},
{
title: "Location",
dataIndex: "location",
// filters: [
// {
// text: "London",
// value: "London"
// },
// {
// text: "New York",
// value: "New York"
// }
// ],
// onFilter: (value, record) => record.address.startsWith(value),
// filterSearch: true,
width: "15%"
},
{
title: "Price",
dataIndex: "price",
// filters: [
// {
// text: "London",
// value: "London"
// },
// {
// text: "New York",
// value: "New York"
// }
// ],
// onFilter: (value, record) => record.address.startsWith(value),
// filterSearch: true,
width: "15%"
},
{
title: "Place",
dataIndex: "place",
// filters: [
// {
// text: "London",
// value: "London"
// },
// {
// text: "New York",
// value: "New York"
// }
// ],
// onFilter: (value, record) => record.address.startsWith(value),
// filterSearch: true,
width: "15%"
},
{
title: "Gift",
dataIndex: "gift",
// filters: [
// {
// text: "London",
// value: "London"
// },
// {
// text: "New York",
// value: "New York"
// }
// ],
// onFilter: (value, record) => record.address.startsWith(value),
// filterSearch: true,
width: "10%"
}
]);
}, []);
console.log("allActivitiesData", allActivitiesData);
const rowSelection = {
selectedRowKeys,
onChange: onSelectChange,
selections: [
Table.SELECTION_ALL,
Table.SELECTION_INVERT,
Table.SELECTION_NONE,
{
key: "odd",
text: "Select Odd Row",
onSelect: changeableRowKeys => {
let newSelectedRowKeys = [];
newSelectedRowKeys = changeableRowKeys.filter((_, index) => {
if (index % 2 !== 0) {
return false;
}
return true;
});
setSelectedRowKeys(newSelectedRowKeys);
}
},
{
key: "even",
text: "Select Even Row",
onSelect: changeableRowKeys => {
let newSelectedRowKeys = [];
newSelectedRowKeys = changeableRowKeys.filter((_, index) => {
if (index % 2 !== 0) {
return true;
}
return false;
});
setSelectedRowKeys(newSelectedRowKeys);
}
}
]
};
return (
<div>
<Table rowSelection={rowSelection} columns={columns} dataSource={data} onChange={onChange} />;
</div>
);
};
export default ActivityListingRBAC;
......@@ -3,6 +3,9 @@ import Layout from "../../../components/layout/Layout";
import { wrapper } from "../../../redux/store";
import Sidebar from "../../../components/layout/VendorDashboardSidebar";
import ActivityListing from "../../../components/vendor/ActivityListing";
import ActivityListingRBAC from "../../../components/vendor/ActivityListingRBAC";
import { getAllCategories, getAllSubCategories } from "../../../redux/actions/categoriesAction";
import { getActivitiesByVendor } from "../../../redux/actions/activityAction";
// import { loadUser } from "../redux/actions/userActions";
// import { wrapper } from "../redux/store";
......@@ -13,7 +16,7 @@ export default function ActivityListingPage() {
<div className="sidebarContainer">
<Sidebar />
<div className="content">
<ActivityListing />
<ActivityListingRBAC />
</div>
</div>
</Layout>
......@@ -24,7 +27,9 @@ export default function ActivityListingPage() {
/** For server side rendering */
export const getServerSideProps = wrapper.getServerSideProps(store => async ({ req, query }) => {
// Get the menu data.
await store.dispatch(getActivitiesByVendor())
await store.dispatch(getAllCategories())
await store.dispatch(getAllSubCategories())
// get the locations data.
// await store.dispatch(getVendorDetails())
......
This diff could not be displayed because it is too large.
import axios from "axios";
import { getSession } from "next-auth/react";
import { CREATE_ACTIVITY_FAIL, CREATE_ACTIVITY_REQUEST, CREATE_ACTIVITY_SUCCESS } from "../constants/activitiesConstants";
import {
CREATE_ACTIVITY_FAIL,
CREATE_ACTIVITY_REQUEST,
CREATE_ACTIVITY_SUCCESS,
GET_ACTIVITIES_FAIL,
GET_ACTIVITIES_REQUEST,
GET_ACTIVITIES_SUCCESS
} from "../constants/activitiesConstants";
import qs from "qs";
import { getLoggedInVendor } from "./vendorActions";
export const createActivity = data => async dispatch => {
console.log("data", data);
......@@ -42,6 +51,78 @@ export const createActivity = data => async dispatch => {
}
};
export const getActivitiesByVendor = () => async dispatch => {
// console.log("data", data);
// const session = await getSession();
// console.log("session", session);
try {
// const vendorConfig = {
// headers: {
// "Content-Type": "application/json",
// Authorization: `Bearer ${session.jwt}`
// }
// };
// const vendorQuery = {
// filters: {
// user: {
// id: { $eq: session.id }
// }
// }
// };
// const vendorQueryString = qs.stringify(vendorQuery, {
// encodeValuesOnly: true
// });
// const vendorResponse = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/vendors/?${vendorQueryString}`, vendorConfig);
// console.log("vendorResponse",vendorResponse.data)
// const loggedinVendor = await getLoggedInVendor()
// console.log("loggedinVendor", loggedinVendor);
// if (!session) {
// return "You are not authenticated, please log in.";
// }
dispatch({
type: GET_ACTIVITIES_REQUEST,
loading: true
});
const config = {
headers: {
"Content-Type": "application/json"
// Authorization: `Bearer ${session.jwt}`
}
};
const query = {
filters: {},
populate: ["masterMonths", "subCategory", "subCategory.category", "timeSlots", "masterPincode", "vendor"]
};
const queryString = qs.stringify(query, {
encodeValuesOnly: true
});
// let activityData = {
// data: {
// ...data
// }
// };
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/experiences?${queryString}`, config);
dispatch({
type: GET_ACTIVITIES_SUCCESS,
payload: response.data
});
return response.data;
} catch (error) {
dispatch({
type: GET_ACTIVITIES_FAIL,
payload: error.response.data
});
}
};
// export const getMasterDays = async () => {
// const config = {
// headers: {
......
......@@ -47,15 +47,14 @@ export const getAllSubCategories = categoryName => async dispatch => {
}
};
const query = {
filters: {
category: {
name: { $eq: categoryName }
}
},
let query = {
filters: {},
populate: ["category"]
};
if (categoryName) {
query.filters.category.name = { $eq: categoryName };
}
const queryString = qs.stringify(query, {
encodeValuesOnly: true
});
......
......@@ -2,4 +2,8 @@ export const CREATE_ACTIVITY_REQUEST = "CREATE_ACTIVITY_REQUEST"
export const CREATE_ACTIVITY_SUCCESS = "CREATE_ACTIVITY_SUCCESS"
export const CREATE_ACTIVITY_FAIL = "CREATE_ACTIVITY_FAIL"
export const GET_ACTIVITIES_REQUEST = "GET_ACTIVITIES_REQUEST"
export const GET_ACTIVITIES_SUCCESS = "GET_ACTIVITIES_SUCCESS"
export const GET_ACTIVITIES_FAIL = "GET_ACTIVITIES_FAIL"
export const CLEAR_ERRORS = "CLEAR_ERRORS";
\ No newline at end of file
import { CREATE_ACTIVITY_FAIL, CREATE_ACTIVITY_REQUEST, CREATE_ACTIVITY_SUCCESS } from "../constants/activitiesConstants";
import { CREATE_ACTIVITY_FAIL, CREATE_ACTIVITY_REQUEST, CREATE_ACTIVITY_SUCCESS, GET_ACTIVITIES_FAIL, GET_ACTIVITIES_REQUEST, GET_ACTIVITIES_SUCCESS } from "../constants/activitiesConstants";
import { CLEAR_ERRORS } from "../constants/vendorConstants";
export const createActivityReducer = (state = {}, action) => {
......@@ -27,4 +27,33 @@ export const createActivityReducer = (state = {}, action) => {
default:
return state;
}
};
\ No newline at end of file
};
export const getActivitiesReducer = (state = {}, action) => {
switch (action.type) {
case GET_ACTIVITIES_REQUEST:
return { loading: true };
case GET_ACTIVITIES_SUCCESS:
return {
loading: false,
allActivitiesData: action.payload
};
case GET_ACTIVITIES_FAIL:
return {
loading: false,
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
\ No newline at end of file
......@@ -5,7 +5,7 @@ import { authReducer, forgotPasswordReducer, loadedUserReducer, resetPasswordRed
import { enquiryReducer } from "./enquiryReducer";
import { displayEnquireNowReducer } from "./enquireNowModalReducer";
import { getVendorDetailsReducer, loggedInVendorReducer, updateVendorReducer } from "./vendorReducers";
import { createActivityReducer } from "./activitiesReducer";
import { createActivityReducer, getActivitiesReducer } from "./activitiesReducer";
import { getAllCategoriesReducer, getAllSubCategoriesReducer } from "./categoryReducer";
const reducers = combineReducers({
......@@ -27,6 +27,7 @@ const reducers = combineReducers({
activityData: createActivityReducer,
categories: getAllCategoriesReducer,
subCategories: getAllSubCategoriesReducer,
allActivitiesData: getActivitiesReducer,
});
export default reducers;
This diff could not be displayed because it is too large.
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!