-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 🎸 create table component and test in order #21
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
Draft
kenmaqqe
wants to merge
22
commits into
dev
Choose a base branch
from
feat/fe-admin
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e5ba0ca
feat: 🎸 create table component and test in order
kenmaqqe 690b537
feat: 🎸 add sort component
kenmaqqe fea857d
feat: 🎸 add customInput component
kenmaqqe 97d4836
refactor: 💡 add yup validation and refactore some code
kenmaqqe f50d330
refactor: 💡 remake custom table using table component from antd
kenmaqqe de03b9a
fix: 🐛 add actions button to table
kenmaqqe 1d97645
feat: 🎸 create custom modal component
kenmaqqe 2d40488
fix: 🐛 refactore and resolve all problems
kenmaqqe 2d5bc07
fix: 🐛 small refactore
kenmaqqe b834c67
small fix and refactore
kenmaqqe 5c7ba78
feat: 🎸 add onClick to actions button and test
kenmaqqe 0a109c4
refactor: 💡 create modal component and remake modals open logic
kenmaqqe b05f141
feat: 🎸 create new modal architecture using entity and modalTyp
kenmaqqe b90e31d
fix: 🐛 resolve all changes
kenmaqqe b0892f2
feat: 🎸 new archirtecture for modal component
kenmaqqe 50b38d0
fix: 🐛 rebase dataSource from orderPage to OrderTableData file
kenmaqqe 65924c9
fix: 🐛 setting up pagination for Table component
kenmaqqe f1b86e1
feat: 🎸 create EditOrder and Delete modal and testing with mock
kenmaqqe 6a00cf9
fix: 🐛 remake modal architecture and resolve changes
kenmaqqe d55d64b
fix: 🐛 resolve changes
kenmaqqe 6e2077c
feat: 🎸 add logic to modal
kenmaqqe 0d1e6b5
fix: 🐛 go use $danger varialbe for danger button styles
kenmaqqe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -14,3 +14,6 @@ vitest.config.*.timestamp* | |
|
|
||
| .nx | ||
| .vscode | ||
|
|
||
| .cursor/rules/nx-rules.mdc | ||
| .github/instructions/nx.instructions.md | ||
This file contains hidden or 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
4 changes: 4 additions & 0 deletions
4
apps/fe-admin/src/components/ActionButtons/ActionButtons.module.scss
This file contains hidden or 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,4 @@ | ||
| .ActionButtons { | ||
| display: flex; | ||
| gap: 10px; | ||
| } |
24 changes: 24 additions & 0 deletions
24
apps/fe-admin/src/components/ActionButtons/ActionButtons.tsx
This file contains hidden or 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,24 @@ | ||
| import React from 'react'; | ||
| import { MdDelete, MdEdit } from 'react-icons/md'; | ||
| import { CustomButton } from '@shopery/ui-shared'; | ||
| import styles from './ActionButtons.module.scss'; | ||
|
|
||
| type ActionButtonsProps = { | ||
| onEdit?: () => void; | ||
| onDelete?: () => void; | ||
| }; | ||
|
|
||
| const ActionButtons = ({ onEdit, onDelete }: ActionButtonsProps) => { | ||
| return ( | ||
| <div className={styles.ActionButtons}> | ||
| <CustomButton onClick={onEdit}> | ||
| <MdEdit /> | ||
| </CustomButton> | ||
| <CustomButton onClick={onDelete}> | ||
| <MdDelete /> | ||
| </CustomButton> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default ActionButtons; |
This file contains hidden or 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 hidden or 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 +1,2 @@ | ||
| export { default as Sidebar } from './Sidebar/Sidebar'; | ||
| export { default as ActionsButtons } from './ActionButtons/ActionButtons'; |
This file contains hidden or 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,86 @@ | ||
| export const dataSource = [ | ||
| { | ||
| id: 1, | ||
| userId: 101, | ||
| totalNumberOfProducts: 2, | ||
| totalPrice: 50, | ||
| status: 'pending', | ||
| }, | ||
| { | ||
| id: 2, | ||
| userId: 102, | ||
| totalNumberOfProducts: 3, | ||
| totalPrice: 75, | ||
| status: 'shipped', | ||
| }, | ||
| { | ||
| id: 3, | ||
| userId: 103, | ||
| totalNumberOfProducts: 1, | ||
| totalPrice: 25, | ||
| status: 'delivered', | ||
| }, | ||
| { | ||
| id: 4, | ||
| userId: 104, | ||
| totalNumberOfProducts: 5, | ||
| totalPrice: 100, | ||
| status: 'pending', | ||
| }, | ||
| { | ||
| id: 5, | ||
| userId: 105, | ||
| totalNumberOfProducts: 4, | ||
| totalPrice: 80, | ||
| status: 'shipped', | ||
| }, | ||
| { | ||
| id: 6, | ||
| userId: 106, | ||
| totalNumberOfProducts: 2, | ||
| totalPrice: 60, | ||
| status: 'delivered', | ||
| }, | ||
| { | ||
| id: 7, | ||
| userId: 107, | ||
| totalNumberOfProducts: 3, | ||
| totalPrice: 90, | ||
| status: 'pending', | ||
| }, | ||
| { | ||
| id: 8, | ||
| userId: 108, | ||
| totalNumberOfProducts: 1, | ||
| totalPrice: 30, | ||
| status: 'shipped', | ||
| }, | ||
| { | ||
| id: 9, | ||
| userId: 109, | ||
| totalNumberOfProducts: 6, | ||
| totalPrice: 120, | ||
| status: 'delivered', | ||
| }, | ||
| { | ||
| id: 10, | ||
| userId: 110, | ||
| totalNumberOfProducts: 2, | ||
| totalPrice: 40, | ||
| status: 'pending', | ||
| }, | ||
| { | ||
| id: 11, | ||
| userId: 111, | ||
| totalNumberOfProducts: 3, | ||
| totalPrice: 70, | ||
| status: 'shipped', | ||
| }, | ||
| { | ||
| id: 12, | ||
| userId: 112, | ||
| totalNumberOfProducts: 4, | ||
| totalPrice: 90, | ||
| status: 'delivered', | ||
| }, | ||
| ]; |
This file contains hidden or 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 @@ | ||
| export { dataSource } from './OrderTableData'; |
This file contains hidden or 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 +1 @@ | ||
| export { default as PageLayout } from './pageLayout/PageLayout'; | ||
| export { default as PageLayout } from './pageLayout/pageLayout'; |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
Empty file.
This file contains hidden or 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,163 @@ | ||
| import { | ||
| CustomButton, | ||
| CustomInput, | ||
| CustomModal, | ||
| CustomSelect, | ||
| CustomTable, | ||
| } from '@shopery/ui-shared'; | ||
| import { useDeferredValue, useState } from 'react'; | ||
| import { Controller, useForm, useWatch } from 'react-hook-form'; | ||
| import ActionButtons from '../../components/ActionButtons/ActionButtons'; | ||
| import { dataSource } from '../../data'; | ||
| import styles from './OrderPage.module.scss'; | ||
|
|
||
| const OrderPage = () => { | ||
| const [orderData, setOrderData] = useState(dataSource); | ||
| const [isEditModalOpen, setIsEditModalOpen] = useState(false); | ||
| const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); | ||
| const [orderId, setOrderId] = useState<number | null>(null); | ||
| const [editStatus, setEditStatus] = useState<string | null>(null); | ||
| const { control } = useForm({ | ||
| defaultValues: { | ||
| search: '', | ||
| }, | ||
| }); | ||
|
|
||
| const columns = [ | ||
| { title: 'Order ID', dataIndex: 'id', key: 'id' }, | ||
| { title: 'User', dataIndex: 'userId', key: 'userId' }, | ||
| { | ||
| title: 'Total number of products', | ||
| dataIndex: 'totalNumberOfProducts', | ||
| key: 'totalNumberOfProducts', | ||
| }, | ||
| { title: 'Total Price', dataIndex: 'totalPrice', key: 'totalPrice' }, | ||
| { title: 'Status', dataIndex: 'status', key: 'status' }, | ||
| { | ||
| title: 'Actions', | ||
| key: 'actions', | ||
| render: (record) => ( | ||
| <ActionButtons | ||
| onEdit={() => handleOpenEditModal(record.id, record.status)} | ||
| onDelete={() => handleOpenDeleteModal(record.id)} | ||
| /> | ||
| ), | ||
| }, | ||
| ]; | ||
|
|
||
| const statusOptions = [ | ||
| { value: 'pending', label: 'Pending' }, | ||
| { value: 'shipped', label: 'Shipped' }, | ||
| { value: 'delivered', label: 'Delivered' }, | ||
| ]; | ||
|
|
||
| const handleOpenEditModal = (id: number, status: string) => { | ||
| setOrderId(id); | ||
| setIsEditModalOpen(true); | ||
| setEditStatus(status); | ||
| }; | ||
|
|
||
| const handleOpenDeleteModal = (id: number) => { | ||
| setOrderId(id); | ||
| setIsDeleteModalOpen(true); | ||
| }; | ||
|
|
||
| const searchValue = useWatch({ control, name: 'search' }); | ||
| const debouncedSearch = useDeferredValue(searchValue?.trim() ?? '', 400); | ||
|
|
||
| const filteredData = orderData.filter((item) => { | ||
| if (!debouncedSearch) return true; | ||
| const searchStr = debouncedSearch.toLowerCase(); | ||
|
|
||
| const matchesSearch = [ | ||
| item.id, | ||
| item.userId, | ||
| item.totalNumberOfProducts, | ||
| item.totalPrice, | ||
| item.status?.toLowerCase(), | ||
| ].some((field) => String(field).includes(searchStr)); | ||
|
|
||
| return matchesSearch; | ||
| }); | ||
|
|
||
| const handleDelete = (id: number) => { | ||
| setOrderData(orderData.filter((item) => item.id !== id)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use prev value |
||
| setIsDeleteModalOpen(false); | ||
| setOrderId(null); | ||
| }; | ||
|
|
||
| const handleSave = () => { | ||
| if (typeof editStatus !== 'string') return; | ||
| setOrderData((prev) => | ||
kenmaqqe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| prev.map((item) => { | ||
| if (item.id === orderId) { | ||
| return { ...item, status: editStatus }; | ||
| } | ||
| return item; | ||
| }) | ||
| ); | ||
| setIsEditModalOpen(false); | ||
| setEditStatus(null); | ||
| setOrderId(null); | ||
| }; | ||
|
|
||
| return ( | ||
| <section className={styles.orderPage}> | ||
| <h1>Orders</h1> | ||
| <form> | ||
| <Controller | ||
| name='search' | ||
| control={control} | ||
| render={({ field, fieldState }) => ( | ||
| <CustomInput | ||
| placeholder='Search...' | ||
| {...field} | ||
| hasError={!!fieldState.error} | ||
| error={fieldState.error?.message} | ||
| /> | ||
| )} | ||
| /> | ||
| </form> | ||
| <CustomSelect | ||
| prefix='Filter by status:' | ||
| options={[{ value: 'all', label: 'All' }, ...statusOptions]} | ||
| /> | ||
| <CustomTable columns={columns} dataSource={filteredData} /> | ||
| <CustomModal | ||
| open={isEditModalOpen} | ||
| onCancel={() => setIsEditModalOpen(false)} | ||
| title='Edit Order' | ||
| footer={ | ||
| <CustomButton variant='fill' onClick={() => handleSave()}> | ||
| Save | ||
| </CustomButton> | ||
| } | ||
| > | ||
| <CustomSelect | ||
| value={editStatus} | ||
| options={statusOptions} | ||
| onChange={(value: string) => setEditStatus(value)} | ||
| /> | ||
| </CustomModal> | ||
| <CustomModal | ||
| open={isDeleteModalOpen} | ||
| onCancel={() => setIsDeleteModalOpen(false)} | ||
| title='Delete Order' | ||
| footer={ | ||
| <CustomButton | ||
| variant='danger' | ||
| onClick={() => { | ||
| handleDelete(orderId as number); | ||
| }} | ||
| > | ||
| Delete | ||
| </CustomButton> | ||
| } | ||
| > | ||
| <p>Are you sure you want to delete this order?</p> | ||
| </CustomModal> | ||
| </section> | ||
| ); | ||
| }; | ||
|
|
||
| export default OrderPage; | ||
This file contains hidden or 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,4 +1,4 @@ | ||
| export { default as DashboardPage } from './DashboardPage'; | ||
| export { default as OrderPage } from './OrderPage'; | ||
| export { default as OrderPage } from './OrderPage/OrderPage'; | ||
| export { default as ProductPage } from './ProductPage'; | ||
| export { default as UserPage } from './UserPage'; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.