add product id
This commit is contained in:
@@ -89,6 +89,10 @@ const DetailPerfomaInvoice: FC = () => {
|
|||||||
{invoice.items?.map((item) => {
|
{invoice.items?.map((item) => {
|
||||||
const discounts = formatItemDiscountDisplay(item);
|
const discounts = formatItemDiscountDisplay(item);
|
||||||
const lineTotal = item.total ?? 0;
|
const lineTotal = item.total ?? 0;
|
||||||
|
const convertToOrderUrl = `${Paths.convertToOrder}?${new URLSearchParams({
|
||||||
|
invoiceItemId: item.id,
|
||||||
|
productId: item.product?.id ?? '',
|
||||||
|
}).toString()}`;
|
||||||
return (
|
return (
|
||||||
<tr key={item.id} className="border-b border-border/50">
|
<tr key={item.id} className="border-b border-border/50">
|
||||||
<td className="py-3">{item.product?.title ?? '-'}</td>
|
<td className="py-3">{item.product?.title ?? '-'}</td>
|
||||||
@@ -105,7 +109,7 @@ const DetailPerfomaInvoice: FC = () => {
|
|||||||
<td className="py-3">
|
<td className="py-3">
|
||||||
{item.id && (
|
{item.id && (
|
||||||
<Link
|
<Link
|
||||||
to={Paths.convertToOrder + '?invoiceItemId=' + item.id}
|
to={convertToOrderUrl}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ const InvoiceItemRow: FC<Props> = ({
|
|||||||
const total = getItemLineTotal(item);
|
const total = getItemLineTotal(item);
|
||||||
const subTotal = getItemSubTotal(item);
|
const subTotal = getItemSubTotal(item);
|
||||||
const isPercentDiscount = item.discountPercent != null;
|
const isPercentDiscount = item.discountPercent != null;
|
||||||
|
const convertToOrderUrl = item.id
|
||||||
|
? `${Paths.convertToOrder}?${new URLSearchParams({
|
||||||
|
invoiceItemId: item.id,
|
||||||
|
productId: item.productId,
|
||||||
|
}).toString()}`
|
||||||
|
: "";
|
||||||
|
|
||||||
const handleProductChange = (e: ChangeEvent<HTMLSelectElement>) => {
|
const handleProductChange = (e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
onChange(index, "productId", e.target.value);
|
onChange(index, "productId", e.target.value);
|
||||||
@@ -183,7 +189,7 @@ const InvoiceItemRow: FC<Props> = ({
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{item.id && (
|
{item.id && (
|
||||||
<Link to={Paths.convertToOrder + '?invoiceItemId=' + item.id}>
|
<Link to={convertToOrderUrl}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onConvertToOrder}
|
onClick={onConvertToOrder}
|
||||||
|
|||||||
@@ -17,9 +17,12 @@ import { Paths } from '@/config/Paths'
|
|||||||
import { extractErrorMessage } from '@/config/func'
|
import { extractErrorMessage } from '@/config/func'
|
||||||
import { useGetAdmins } from '../admin/hooks/useAdminData'
|
import { useGetAdmins } from '../admin/hooks/useAdminData'
|
||||||
|
|
||||||
const getInitialValues = (invoiceItemId: string | null): ConvertToOrderItemType => ({
|
const getInitialValues = (
|
||||||
|
invoiceItemId: string | null,
|
||||||
|
productId: string | null
|
||||||
|
): ConvertToOrderItemType => ({
|
||||||
invoiceItemId: invoiceItemId ?? '',
|
invoiceItemId: invoiceItemId ?? '',
|
||||||
productId: '',
|
productId: productId ?? '',
|
||||||
userId: '',
|
userId: '',
|
||||||
typeId: '',
|
typeId: '',
|
||||||
estimatedDays: 0,
|
estimatedDays: 0,
|
||||||
@@ -46,6 +49,7 @@ const ConvertToOrders: FC = () => {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [searchParams] = useSearchParams()
|
const [searchParams] = useSearchParams()
|
||||||
const invoiceItemId = searchParams.get('invoiceItemId')
|
const invoiceItemId = searchParams.get('invoiceItemId')
|
||||||
|
const productId = searchParams.get('productId')
|
||||||
const multiUpload = useMultiUpload()
|
const multiUpload = useMultiUpload()
|
||||||
const [attachmentFiles, setAttachmentFiles] = useState<File[]>([])
|
const [attachmentFiles, setAttachmentFiles] = useState<File[]>([])
|
||||||
const { data: categories } = useGetCategory()
|
const { data: categories } = useGetCategory()
|
||||||
@@ -56,7 +60,7 @@ const ConvertToOrders: FC = () => {
|
|||||||
const { mutate: converToOrder, isPending } = useConverToOrder()
|
const { mutate: converToOrder, isPending } = useConverToOrder()
|
||||||
|
|
||||||
const formik = useFormik<ConvertToOrderItemType>({
|
const formik = useFormik<ConvertToOrderItemType>({
|
||||||
initialValues: getInitialValues(invoiceItemId),
|
initialValues: getInitialValues(invoiceItemId, productId),
|
||||||
validationSchema: getValidationSchema(invoiceItemId),
|
validationSchema: getValidationSchema(invoiceItemId),
|
||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
onSubmit: async (values) => {
|
onSubmit: async (values) => {
|
||||||
@@ -72,7 +76,7 @@ const ConvertToOrders: FC = () => {
|
|||||||
const payload: ConvertToOrderItemType = {
|
const payload: ConvertToOrderItemType = {
|
||||||
...values,
|
...values,
|
||||||
invoiceItemId: invoiceItemId ?? values.invoiceItemId ?? '',
|
invoiceItemId: invoiceItemId ?? values.invoiceItemId ?? '',
|
||||||
productId: invoiceItemId ? undefined : values.productId,
|
productId: values.productId || undefined,
|
||||||
userId: invoiceItemId ? undefined : values.userId,
|
userId: invoiceItemId ? undefined : values.userId,
|
||||||
estimatedDays: Number(values.estimatedDays),
|
estimatedDays: Number(values.estimatedDays),
|
||||||
description: values.description || undefined,
|
description: values.description || undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user