I'm currently working on a React/Ts app with a ruby on rails backend, when i try to get the data from a certain foreign key i get a unexpected response (This is the code on frontend):
const fetchRecord = async (productsResponse: any, paymentsResponse: any) => {
const res = await api.get(`${API_PATH}/${recordId}`);
setValue('user', { id: res.data.customer_data.id, label: res.data.customer_data.name });
setValue('paymentGateway', res.data.payment_gateway);
setValue('orderSdr', { id: res.data.order_sdr.id, label: res.data.order_sdr.name });
setValue('expirationDate', res.data.expiration_date?.split('T')[0]);
setValue('installments', res.data.installments);
setValue('installmentSuggestion', res.data.installment_suggestion);
The line with the problem is 'orderSdr' The code for the input:
<InputLabel htmlFor="order-consultant">SDR do Pedido</InputLabel>
<Controller
name="orderSdr"
control={control}
render={({ field: { onChange, value, ...field } }) => (
<FormControl fullWidth>
<Autocomplete
id="order-consultant"
options={consultants}
noOptionsText="Nenhum resultado encontrado!"
disablePortal
onChange={(_, item) => onChange(item)}
isOptionEqualToValue={
(option: any, newValue: any) => option.id === newValue.id
}
value={value || null}
renderInput={params => (
<TextField
{...params}
{...field}
size="small"
color="secondary"
variant="outlined"
disabled={isSubmitting}
error={errors.orderSdr !== undefined}
/>
)}
/>
{errors.orderSdr?.type && <FormHelperText error>{errors.orderSdr?.message}</FormHelperText>}
</FormControl>
)}
/>
I'm doing something wrong? (If you need more context don't mind to ask)