From 7043c9a2f4a7fddc1d04e4d17b0721adb0ab7dfb Mon Sep 17 00:00:00 2001 From: Samandar Turg'unboev Date: Wed, 28 May 2025 15:00:31 +0500 Subject: [PATCH] edit packet --- .../boxes-create/DashboardCreateBox.tsx | 67 +++++++++---------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/src/routes/private/boxes-create/DashboardCreateBox.tsx b/src/routes/private/boxes-create/DashboardCreateBox.tsx index 8f4ade8..1764912 100644 --- a/src/routes/private/boxes-create/DashboardCreateBox.tsx +++ b/src/routes/private/boxes-create/DashboardCreateBox.tsx @@ -119,23 +119,23 @@ const DashboardCreateBoxPage = ({ initialValues, partiesData }: Props) => { box_size: '50x40x40', status: 'READY_TO_INVOICE', cargoId: initialValues?.client_id, - // passportId: {value: initialValues?.passportId}, + passportId: { value: initialValues?.passportId }, ...(editMode ? {} : { - products_list: [ - { - id: '', - cargoId: '', - trekId: '', - name: '', - nameRu: '', - amount: '', - weight: '', - price: '', - }, - ], - }), + products_list: [ + { + id: '', + cargoId: '', + trekId: '', + name: '', + nameRu: '', + amount: '', + weight: '', + price: '', + }, + ], + }), ...initialValues, }, }); @@ -184,11 +184,11 @@ const DashboardCreateBoxPage = ({ initialValues, partiesData }: Props) => { dependencies: [cargoId], placeholderData: [], // Kerak emas, chunki server PageAble qaytarmayapti onSuccess(data) { - // if (data?.data.data?.[0]?.id) { - // setValue("passportId", initialValues?.passportId) - // setValue('passport_id', data.data.data[0].id); - // setSelectedPassport(data.data.data[0]); // Birinchi elementni tanlash - // } + if (data?.data.data?.[0]?.id) { + setValue("passportId", initialValues?.passportId) + setValue('passport_id', data.data.data[0].id); + setSelectedPassport(data.data.data[0]); // Birinchi elementni tanlash + } }, }); @@ -258,10 +258,9 @@ const DashboardCreateBoxPage = ({ initialValues, partiesData }: Props) => { if (editMode) { const updateBody: UpdateBoxBodyType = { cargoId: values.client_id, - passportId: values.passportId.value, + passportId: values.passportId?.value || values.passport_id, status: values.status, packetId: initialValues?.packetId, - items: values.products_list.map((item: any) => { const _price = +item.price ? +item.price : 0; const _amount = +item.amount ? +item.amount : 0; @@ -269,9 +268,7 @@ const DashboardCreateBoxPage = ({ initialValues, partiesData }: Props) => { return { id: item.id, - // cargoId: item.cargoId, trekId: item.trekId, - // name: item.name + (item.nameRu ? ` / ${item.nameRu}` : ''), name: item.name, nameRu: item?.nameRu, weight: +item.weight, @@ -380,11 +377,11 @@ const DashboardCreateBoxPage = ({ initialValues, partiesData }: Props) => { label: string; value: BoxStatus; }[] = [ - { - label: t('READY_TO_INVOICE'), - value: 'READY_TO_INVOICE', - }, - ]; + { + label: t('READY_TO_INVOICE'), + value: 'READY_TO_INVOICE', + }, + ]; if (isAdmin) { p.push({ @@ -429,15 +426,15 @@ const DashboardCreateBoxPage = ({ initialValues, partiesData }: Props) => { defaultValue={ editMode ? { - value: initialValues.partyId, - label: initialValues.partyName, - } + value: initialValues.partyId, + label: initialValues.partyName, + } : partiesData?.length - ? { + ? { value: partiesData[0].value, label: partiesData[0].label, } - : null + : null } styles={selectDefaultStyles} noOptionsMessage={() => t('not_found')} @@ -555,7 +552,7 @@ const DashboardCreateBoxPage = ({ initialValues, partiesData }: Props) => { if (!Number.isNaN(p)) { totalPrice = p; } - } catch (error) {} + } catch (error) { } return ( @@ -710,7 +707,7 @@ const DashboardCreateBoxPage = ({ initialValues, partiesData }: Props) => { value={totalPrice} mainBorderColor='#D8D8D8' placeholder={t('total_price')} - // {...register(`products_list.${index}.totalPrice`, { required: requiredText })} + // {...register(`products_list.${index}.totalPrice`, { required: requiredText })} />