Skip to content

Commit

Permalink
add pages
Browse files Browse the repository at this point in the history
  • Loading branch information
filipKovachev committed Nov 14, 2024
1 parent df39e9f commit 2e42e7c
Show file tree
Hide file tree
Showing 39 changed files with 1,028 additions and 255 deletions.
7 changes: 6 additions & 1 deletion examples/kendo-react-e-commerce-astro-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@
"@astrojs/check": "^0.9.4",
"@astrojs/react": "^3.6.2",
"@progress/kendo-data-query": "^1.7.0",
"@progress/kendo-drawing": "^1.21.0",
"@progress/kendo-drawing": "^1.21.1",
"@progress/kendo-licensing": "^1.3.5",
"@progress/kendo-react-animation": "^8.5.0",
"@progress/kendo-react-buttons": "^8.5.0",
"@progress/kendo-react-common": "^8.5.0",
"@progress/kendo-react-data-tools": "^8.5.0",
"@progress/kendo-react-dateinputs": "^8.5.0",
"@progress/kendo-react-dropdowns": "^8.5.0",
"@progress/kendo-react-form": "^8.5.0",
"@progress/kendo-react-grid": "^8.5.0",
"@progress/kendo-react-indicators": "^8.5.0",
"@progress/kendo-react-inputs": "^8.5.0",
"@progress/kendo-react-intl": "^8.5.0",
"@progress/kendo-react-layout": "^8.5.0",
"@progress/kendo-react-chart-wizard": "^8.5.0",
"@progress/kendo-react-notification": "^8.5.0",
"@progress/kendo-react-popup": "^8.5.0",
"@progress/kendo-react-progressbars": "^8.5.0",
"@progress/kendo-react-treeview": "^8.5.0",
"@progress/kendo-svg-icons": "^3.3.0",
Expand Down
231 changes: 231 additions & 0 deletions examples/kendo-react-e-commerce-astro-app/src/components/AdminView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import * as React from 'react';
import { getter } from '@progress/kendo-react-common';
import {
Grid,
GridColumn,
GridSelectionChangeEvent,
GridHandle,
getSelectedState,
GridKeyDownEvent,
getSelectedStateFromKeyDown,
GridSortChangeEvent,
} from '@progress/kendo-react-grid';
import {
ChartWizard,
getWizardDataFromGridSelection,
} from '@progress/kendo-react-chart-wizard';
import { Button } from '@progress/kendo-react-buttons';
import { orderBy, groupBy } from '@progress/kendo-data-query';
import { chartAreaStackedIcon } from '@progress/kendo-svg-icons';
import { sampleData, SampleDataItem } from '../data/shared-gd-sampleChartData';
import { Pager, PageChangeEvent } from '@progress/kendo-react-data-tools';

const DATA_ITEM_KEY = 'ID';
const SELECTED_FIELD = 'selected';
const idGetter = getter(DATA_ITEM_KEY);

interface SelectedState {
[id: string]: boolean | number[];
}

interface PageState {
skip: number;
take: number;
}

const AdminView: React.FC = () => {
const gridRef = React.useRef<GridHandle>(null);
const [selectedState, setSelectedState] = React.useState<SelectedState>({});
const [sort, setSort] = React.useState<{ field: string; dir: 'asc' | 'desc' }[]>([
{ field: 'Sales', dir: 'desc' },
]);
const [showChartWizard, setShowChartWizard] = React.useState<boolean>(false);
const [chartData, setChartData] = React.useState<SampleDataItem[]>([]);
const [top3SalesData, setTop3SalesData] = React.useState<SampleDataItem[]>([]);
const [top3Visible, setTop3Visible] = React.useState<boolean>(false);
const [page, setPage] = React.useState<PageState>({ skip: 0, take: 4 });

const pageChange = (event: PageChangeEvent) => {
setPage(event.page);
};

const data = sampleData.map((item) => ({
...item,
[SELECTED_FIELD]: selectedState[idGetter(item)],
}));

const pagedData = orderBy(data, sort).slice(page.skip, page.skip + page.take);

const onSelectionChange = (event: GridSelectionChangeEvent) => {
const newSelectedState = getSelectedState({
event,
selectedState,
dataItemKey: DATA_ITEM_KEY,
});
setSelectedState(newSelectedState);
};

const onKeyDown = (event: GridKeyDownEvent) => {
const newSelectedState = getSelectedStateFromKeyDown({
event,
selectedState,
dataItemKey: DATA_ITEM_KEY,
});
setSelectedState(newSelectedState);
};

const disabled = Object.keys(selectedState).length === 0;

const handleSelectedChart = React.useCallback(() => {
if (gridRef.current) {
const chartWizardData = getWizardDataFromGridSelection({
grid: gridRef.current,
data: sampleData,
selectedState,
dataItemKey: DATA_ITEM_KEY,
});

setChartData(chartWizardData);
setShowChartWizard(true);
} else {
console.error('Grid reference is not available.');
}
}, [selectedState]);

const handleTop3Sales = React.useCallback(() => {
const selectedData = getWizardDataFromGridSelection({
grid: gridRef.current,
data: sampleData,
selectedState,
dataItemKey: DATA_ITEM_KEY,
});

const sortedTop3Sales = selectedData
.sort(
(a, b) =>
b.find((field) => field.field === 'Total Sales').value -
a.find((field) => field.field === 'Total Sales').value
)
.slice(0, 3);

setTop3SalesData(sortedTop3Sales);
setTop3Visible(true);
}, [selectedState]);

const URLImageCell: React.FC<{ dataItem: SampleDataItem; field?: string }> = ({
dataItem,
field,
}) => {
const imageUrl = dataItem[field || 'URL'];
return (
<td>
<img src={imageUrl} alt="Product" style={{ width: '100px', height: 'auto' }} />
</td>
);
};

const MyPager: React.FC<{
skip: number;
take: number;
total: number;
onPageChange: (event: PageChangeEvent) => void;
}> = (props) => {
return (
<div style={{ overflow: 'hidden', padding: '10px' }}>
<Pager
responsive={true}
skip={props.skip}
take={props.take}
total={props.total}
onPageChange={props.onPageChange}
buttonCount={5}
info={true}
previousNext={true}
type="numeric"
pageSizes={[4, 10, 15, 20]}
pageSizeValue={props.take}
/>
</div>
);
};

return (
<>
<div style={{ marginBottom: '10px' }}>
<Button
svgIcon={chartAreaStackedIcon}
onClick={handleSelectedChart}
disabled={disabled}
style={{ marginRight: '10px' }}
>
Chart of Selected Data
</Button>
<Button svgIcon={chartAreaStackedIcon} onClick={handleTop3Sales}>
Top 3 Sales per Category
</Button>
</div>
<Grid
ref={gridRef}
style={{ height: '500px' }}
data={pagedData}
dataItemKey={DATA_ITEM_KEY}
selectedField={SELECTED_FIELD}
skip={page.skip}
take={page.take}
total={data.length}
pageable={true}
onPageChange={pageChange}
pager={(pagerProps) => <MyPager {...pagerProps} />}
selectable={{
enabled: true,
drag: true,
mode: 'multiple',
}}
navigatable={true}
onSelectionChange={onSelectionChange}
onKeyDown={onKeyDown}
sortable={true}
sort={sort}
onSortChange={(e: GridSortChangeEvent) => {
setSort(e.sort);
}}
>
<GridColumn field="URL" title="Product" cell={URLImageCell} />
<GridColumn field="Product" title="Name" />
<GridColumn field="SKU" title="SKU" />
<GridColumn field="Category" title="Category" />
<GridColumn field="Price" title="Price" />
<GridColumn field="Quantity" title="Quantity" />
<GridColumn field="Sales" title="Total Sales" />
</Grid>

{showChartWizard && (
<ChartWizard
data={chartData}
series={[
{
field: 'value',
categoryField: 'category',
},
]}
onClose={() => setShowChartWizard(false)}
/>
)}

{top3Visible && (
<ChartWizard
data={top3SalesData}
series={[
{
field: 1,
categoryField: 0,
},
]}
onClose={() => setTop3Visible(false)}
/>
)}
</>
);
};

export default AdminView;
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Button } from "@progress/kendo-react-buttons";
import { BackgroundImageProps } from "../data/types";
import { useNavigate } from "react-router-dom";

export const BackgroundImage = (props: BackgroundImageProps) => {
const { img, title, subtitle, buttonText } = props;
const navigate = useNavigate();

const onButtonClick = () => {
navigate('/products')
}

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@

import { useNavigate } from "react-router-dom";
import { CategoryListProps } from "../data/types";
import { Button } from "@progress/kendo-react-buttons";
import { CardDescriptor } from "../data/types";

export const CategoryList: React.FC<CategoryListProps> = ({ data, title, subtitle, colSpan = 4 }) => {
const navigate = useNavigate();

const onNavigate = (card: CardDescriptor) => {
console.log(card);
if (card.collectionText === `Collection \"AURELIA\"`) {
navigate("/category")
}
}

Expand Down
101 changes: 101 additions & 0 deletions examples/kendo-react-e-commerce-astro-app/src/components/Contacts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React from 'react';
import { Layout } from '../components/Layout';
import CardNumber from '../components/CardNumber';
import ExpiryDate from '../components/ExpiryDate';
import PasswordInput from '../components/PasswordInput';
import EmailInput from '../components/EmailInput';
import CardHolder from '../components/CardHolder';
import CityInput from '../components/CityInput';
import PhoneInput from '../components/PhoneInput';
import AppointmentInput from '../components/AppointmentInput';
import DateChooserInput from '../components/DateChooserInput';
import ContactsRadioButtons from '../components/ContactsRadioButtons'
import { BackgroundImage } from '../components/BackgroundImage';
import contactsImage from '@/assets/contactsImage.png';
import { Button } from '@progress/kendo-react-buttons';

import {
Form,
Field,
FormElement,
FieldWrapper,
} from '@progress/kendo-react-form';
import { RadioButton } from '@progress/kendo-react-inputs';
import { Label } from '@progress/kendo-react-labels';

import creditCards from '../assets/creditCards.png';

const Contacts: React.FC = () => {

const onSubmitClick = () => {
window.location.href="/thankyou"2
};

return (
<Layout>
<div className="k-d-flex k-flex-col k-align-items-center k-py-12 k-px-4 k-gap-10">
<div className="k-d-grid k-grid-cols-12 k-gap-8 k-w-full">
<div className="k-col-span-6 k-col-start-1">
<h1>Get in touch</h1>
<p>If you have any questions, contact us</p>
<Form
render={() => (
<FormElement>
<div className="k-form-layout k-d-grid k-gap-y-6 k-gap-x-4">
<FieldWrapper className="k-col-span-1">
<Label> Full Name </Label>
<Field name="fullName" component={CardHolder} />
</FieldWrapper>
<FieldWrapper className="k-col-span-1">
<Label> Email </Label>
<Field name="email" component={EmailInput} />
</FieldWrapper>
<FieldWrapper className="k-col-span-1">
<Label> Phone Number </Label>
<Field name="phoneNumber" component={PhoneInput} />
</FieldWrapper>
<div className="k-d-flex k-flex-col k-align-items-start k-gap-4">
<p>Type of customer</p>
<ContactsRadioButtons/>
</div>
<FieldWrapper className="k-col-span-1">
<Field name="city" component={CityInput} />
</FieldWrapper>
<FieldWrapper className="k-col-span-1">
<Field name="appointment" component={AppointmentInput} />
</FieldWrapper>
<FieldWrapper className="k-col-span-1">
<Label> Date </Label>
<Field name="date" component={DateChooserInput} />
</FieldWrapper>
</div>
</FormElement>
)}
/>
<Button
className="k-mt-6"
onClick={onSubmitClick}
themeColor={'primary'}
>
Book a Slot
</Button>
</div>
<div className="k-col-span-5 k-col-start-8 k-d-flex k-flex-col k-align-items-start">
<img
src={contactsImage}
alt="Contacts"
style={{
maxWidth: '630px',
maxHeight: '580px',
width: '100%',
height: 'auto',
}}
/>
</div>
</div>
</div>
</Layout>
);
};

export default Contacts;
Loading

0 comments on commit 2e42e7c

Please sign in to comment.