From b96e7403d013f517a5bd8a0945b76f5c27ebdb74 Mon Sep 17 00:00:00 2001 From: Samandar Turg'unboev Date: Thu, 29 May 2025 12:36:30 +0500 Subject: [PATCH 1/2] search --- src/hooks/useInput.ts | 8 ++- .../DashboardCreateRealBox.tsx | 52 +++++++++++-------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/hooks/useInput.ts b/src/hooks/useInput.ts index 3be2466..8ed6f7f 100644 --- a/src/hooks/useInput.ts +++ b/src/hooks/useInput.ts @@ -8,8 +8,12 @@ import { ChangeEvent, useState } from 'react'; const useInput = (initialValue: string) => { const [value, setValue] = useState(initialValue); - const handleChange = (event: ChangeEvent) => { - setValue(event.target.value); + const handleChange = (event: ChangeEvent | string) => { + if (typeof event === 'string') { + setValue(event); + } else if (event?.target) { + setValue(event.target.value); + } }; return { diff --git a/src/routes/private/real-boxes-create/DashboardCreateRealBox.tsx b/src/routes/private/real-boxes-create/DashboardCreateRealBox.tsx index f52b985..daa4bd4 100644 --- a/src/routes/private/real-boxes-create/DashboardCreateRealBox.tsx +++ b/src/routes/private/real-boxes-create/DashboardCreateRealBox.tsx @@ -20,6 +20,7 @@ import { useMyTranslation } from '@/hooks/useMyTranslation'; import { FormValues, RealCreateBoxBodyType, UpdateRealBoxBodyType } from '@/data/real-box/real-box.model'; import get from 'lodash.get'; import useRequest from '@/hooks/useRequest'; +import useInput from '@/hooks/useInput'; const StyledCreateBox = styled(Box)` .item-row { @@ -48,6 +49,7 @@ interface Props { const DashboardCreateRealBoxPage = ({ initialValues, partiesData }: Props) => { const { user, isAdmin: isAdminUser } = useAuthContext(); const editMode = !!initialValues?.id; + const { value: keyword, onChange: handleKeyword, setValue: setKeyword } = useInput(''); const t = useMyTranslation(); const params = useSearchParams(); const { push } = useMyNavigation(); @@ -65,6 +67,8 @@ const DashboardCreateRealBoxPage = ({ initialValues, partiesData }: Props) => { finished: false, }); + console.log(keyword, "keyword"); + const { register, control, @@ -116,6 +120,7 @@ const DashboardCreateRealBoxPage = ({ initialValues, partiesData }: Props) => { () => box_requests.getAll({ partyId: partyId, + cargoId: keyword }), { selectData: (data) => data?.data?.data ?? [], @@ -287,6 +292,7 @@ const DashboardCreateRealBoxPage = ({ initialValues, partiesData }: Props) => { { paketField.onChange(newValue?.value ?? ''); + handleKeyword(newValue?.label ?? ''); }} defaultValue={ editMode && initialValues?.paketIds?.[index] @@ -312,6 +318,7 @@ const DashboardCreateRealBoxPage = ({ initialValues, partiesData }: Props) => { try { const res = await box_requests.getAll({ partyId, + cargoId: inputValue, }); return res.data.data.data.map((box: any) => ({ label: box.box_name || box.name || `Box ${box.id}`, @@ -330,35 +337,34 @@ const DashboardCreateRealBoxPage = ({ initialValues, partiesData }: Props) => { {requiredText} )} - {fields.length > 1 && ( - - removePaket(index)} - > - - - - )} + removePaket(index)} + > + + ))} - - } - onClick={appendPaket} - > - {t('add_more')} - - + } + > + {t('add_packet')} + - - {editMode ? t('update') : t('create')} + + {editMode ? t('update_box') : t('create_box')} From 26fdc3c67a942542a4dbe3a10444812d5a56eaaf Mon Sep 17 00:00:00 2001 From: Samandar Turg'unboev Date: Thu, 29 May 2025 12:54:30 +0500 Subject: [PATCH 2/2] real_box update --- src/hooks/useInput.ts | 8 ++------ .../private/real-boxes-create/DashboardCreateRealBox.tsx | 2 +- src/routes/private/real-boxes/DashboardRealBoxesPage.tsx | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/hooks/useInput.ts b/src/hooks/useInput.ts index 8ed6f7f..3be2466 100644 --- a/src/hooks/useInput.ts +++ b/src/hooks/useInput.ts @@ -8,12 +8,8 @@ import { ChangeEvent, useState } from 'react'; const useInput = (initialValue: string) => { const [value, setValue] = useState(initialValue); - const handleChange = (event: ChangeEvent | string) => { - if (typeof event === 'string') { - setValue(event); - } else if (event?.target) { - setValue(event.target.value); - } + const handleChange = (event: ChangeEvent) => { + setValue(event.target.value); }; return { diff --git a/src/routes/private/real-boxes-create/DashboardCreateRealBox.tsx b/src/routes/private/real-boxes-create/DashboardCreateRealBox.tsx index daa4bd4..16afe22 100644 --- a/src/routes/private/real-boxes-create/DashboardCreateRealBox.tsx +++ b/src/routes/private/real-boxes-create/DashboardCreateRealBox.tsx @@ -49,7 +49,7 @@ interface Props { const DashboardCreateRealBoxPage = ({ initialValues, partiesData }: Props) => { const { user, isAdmin: isAdminUser } = useAuthContext(); const editMode = !!initialValues?.id; - const { value: keyword, onChange: handleKeyword, setValue: setKeyword } = useInput(''); + const [keyword, handleKeyword] = useState(''); const t = useMyTranslation(); const params = useSearchParams(); const { push } = useMyNavigation(); diff --git a/src/routes/private/real-boxes/DashboardRealBoxesPage.tsx b/src/routes/private/real-boxes/DashboardRealBoxesPage.tsx index cb31550..8f4a660 100644 --- a/src/routes/private/real-boxes/DashboardRealBoxesPage.tsx +++ b/src/routes/private/real-boxes/DashboardRealBoxesPage.tsx @@ -54,7 +54,7 @@ const DashboardRealBoxesPage = (props: Props) => { () => real_box_requests.getAll({ page: page, - cargoId: keyword, + boxName: keyword, status: boxStatusFilter, direction: 'desc', sort: 'id',