Задание массива из таблицы. React
Всем привет. Я разрабатываю страничку и у меня возникает несколько проблем. Первая и самая важная, когда я пытаюсь вызвать последнее API MoveProperty у меня вылетает 400 ошибка. Это вызвано тем что вместо одного из параметров я передаю пустой массив.
const handleMoveAccount = () => {
const request = {
sourceClientId: clientID,
propertyId: propertyID,
destinationClientId: destinationClient,
useExistingSources: existingSources,
useExistingMerchantAccounts: existingMerchantAccounts,
accountIds: selectedAccountsToMove.accountId, // here set empty array[]
};
console.log(clientID, propertyID, destinationClient);
console.log(selectedAccountsToMove);
moveProperty(request);
};
У меня вопрос следующего рода, в чем я ошибся при создании массива? Как я понимаю в этот массив должна была записываться вторая таблица и там бы я уже передавал этот selectedAccountsToMove.accountId. My code:
import React, { useState } from 'react';
import { Spin, Select, Button, Form, notification, Checkbox, Typography } from 'antd';
import PropTypes from 'prop-types';
import { useFetch, usePromise } from 'XXX';
import * as apiService from 'services/ApiService';
import AccountTypesV2 from 'components/AccountTypesV2';
import AccountsV2 from 'components/AccountsV2';
import { LAYOUT, TAIL_LAYOUT } from 'constants/layouts';
import { useQueryParams } from 'hooks/useQueryParams';
import styles from './MovePropertyV2.scss';
const MovePropertyV2 = () => {
const [clientID, propertyID] = useQueryParams();
const onFail = (error) => notification.error({ message: error });
const onSuccess = (response) => {
if (response[0].includes('Exception')) {
notification.error({ message: response });
} else {
notification.success({ message: response });
}
};
const [{ isLoading: IsMoveProperty }, moveProperty] = usePromise(apiService.moveProperty, { onFail, onSuccess });
const [clients, isClientLoading] = useFetch(apiService.getAllActiveClents);
// const handleFormFinish = (formValue) => console.log(formValue);
/* const [{ data: accounts, isLoading }, fetchAccounts, clientsId] = usePromise(
apiService.getAccountsByAccountTypes, { onFail, onSuccess }
); */
const [{ data: accounts, isLoading }, fetchAccounts] = usePromise(
apiService.getAccountsByAccountTypes, { onFail, onSuccess }
);
const [selectedAccountTypes, setSelectedItems] = useState([]);
const [selectedAccountsToMove, setSelectedAccountsToMove] = useState([]);
console.log(selectedAccountTypes);
console.log(selectedAccountsToMove);
const [destinationClient, setDestinationClient] = useState();
const [existingSources, setExistingSources] = useState(false);
const [existingMerchantAccounts, setExistingMerchantAccounts] = useState(false);
const handleMoveAccount = () => {
const request = {
sourceClientId: clientID,
propertyId: propertyID,
destinationClientId: destinationClient,
useExistingSources: existingSources,
useExistingMerchantAccounts: existingMerchantAccounts,
accountIds: selectedAccountsToMove.accountId,
};
console.log(clientID, propertyID, destinationClient);
console.log(selectedAccountsToMove);
moveProperty(request);
};
// console.log(clientId, selectedAccountTypes);
const accountSearch = () => {
const requestData = {
clientId: parseInt(clientID, 10),
accountTypes: selectedAccountTypes,
};
fetchAccounts(requestData);
};
return (
<Spin spinning={isLoading}>
<Typography.Title>Move Property</Typography.Title>
<Form {...LAYOUT} onFinish={IsMoveProperty}>
<Form.Item {...TAIL_LAYOUT}>
<Select
placeholder="Destination Client Name"
onChange={setDestinationClient}
loading={isClientLoading}
>
{clients.map((client) => (
<Select.Option key={client.id} value={client.id}>
{client.name}
</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item {...TAIL_LAYOUT}>
<Checkbox onChange={setExistingSources}>Use existing Source</Checkbox>
</Form.Item>
<Form.Item {...TAIL_LAYOUT}>
<Checkbox onChange={setExistingMerchantAccounts}>Use existing merchant accounts</Checkbox>
</Form.Item>
<Form.Item {...TAIL_LAYOUT}>
<AccountTypesV2 onSelectingItems={setSelectedItems} />
</Form.Item>
<Form.Item {...TAIL_LAYOUT}>
<Button htmlType="submit" onClick={accountSearch} className={styles.submitButton}>Search Account</Button>
</Form.Item>
<Form.Item {...TAIL_LAYOUT}>
{accounts
&& <AccountsV2 accounts={accounts} onSelectingAccountsItems={setSelectedAccountsToMove} />}
</Form.Item>
<Form.Item {...TAIL_LAYOUT}>
<Button htmlType="submit" onClick={handleMoveAccount} className={styles.submitButton}>Move Property</Button>
</Form.Item>
</Form>
</Spin>
);
};
MovePropertyV2.propTypes = {
accountId: PropTypes.arrayOf(PropTypes.shape({})),
onSelectingItems: PropTypes.func,
};
MovePropertyV2.defaultProps = {
accountId: [],
onSelectingItems: () => { },
};
export default MovePropertyV2;
Помимо этого у меня вылетает такая ошибка:
