-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df39e9f
commit 2e42e7c
Showing
39 changed files
with
1,028 additions
and
255 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
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
231 changes: 231 additions & 0 deletions
231
examples/kendo-react-e-commerce-astro-app/src/components/AdminView.tsx
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,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; |
3 changes: 0 additions & 3 deletions
3
examples/kendo-react-e-commerce-astro-app/src/components/BackgroundImage.tsx
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
3 changes: 0 additions & 3 deletions
3
examples/kendo-react-e-commerce-astro-app/src/components/CategoryList.tsx
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
101 changes: 101 additions & 0 deletions
101
examples/kendo-react-e-commerce-astro-app/src/components/Contacts.tsx
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,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; |
Oops, something went wrong.