mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
refactor(FE-63): remove debug logging from form submission and movement handlers
This commit is contained in:
@@ -68,27 +68,15 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
validateOnMount: false,
|
validateOnMount: false,
|
||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
onSubmit: async (values) => {
|
onSubmit: async (values) => {
|
||||||
console.log('=== FORM SUBMIT DEBUG ===');
|
|
||||||
console.log('1. Form values received:', values);
|
|
||||||
|
|
||||||
setMovementFormErrorMessage('');
|
setMovementFormErrorMessage('');
|
||||||
const documents: File[] = [];
|
const documents: File[] = [];
|
||||||
const deliveriesPayload = values.deliveries.map((d, idx) => {
|
const deliveriesPayload = values.deliveries.map((d, idx) => {
|
||||||
let documentIndex = 0;
|
let documentIndex = 0;
|
||||||
|
|
||||||
console.log(`2. Processing delivery ${idx}:`, {
|
|
||||||
driver_name: d.driver_name,
|
|
||||||
document: d.document,
|
|
||||||
documentType: d.document instanceof File ? 'File' : typeof d.document,
|
|
||||||
documentSize: d.document instanceof File ? d.document.size : 'N/A',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (d.document && d.document instanceof File) {
|
if (d.document && d.document instanceof File) {
|
||||||
documents.push(d.document);
|
documents.push(d.document);
|
||||||
documentIndex = documents.length - 1;
|
documentIndex = documents.length - 1;
|
||||||
console.log(` → Document added at index ${documentIndex}`);
|
|
||||||
} else {
|
} else {
|
||||||
console.log(` → No document for delivery ${idx}, using index 0`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -117,21 +105,6 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
deliveries: deliveriesPayload,
|
deliveries: deliveriesPayload,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('3. Final payload structure:', {
|
|
||||||
...payload,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
'4. Document indices in deliveries:',
|
|
||||||
deliveriesPayload.map((d, i) => ({
|
|
||||||
delivery: i,
|
|
||||||
document_index: d.document_index,
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log('5. Total documents:', documents.length);
|
|
||||||
console.log('=== END SUBMIT DEBUG ===');
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'add':
|
case 'add':
|
||||||
await createMovementHandler(payload, documents);
|
await createMovementHandler(payload, documents);
|
||||||
|
|||||||
@@ -17,40 +17,20 @@ export const useMovementFormHandlers = (initialValuesId?: number) => {
|
|||||||
|
|
||||||
const createMovementHandler = useCallback(
|
const createMovementHandler = useCallback(
|
||||||
async (payload: CreateMovementPayload, documents: File[] = []) => {
|
async (payload: CreateMovementPayload, documents: File[] = []) => {
|
||||||
console.log('=== CREATE HANDLER DEBUG ===');
|
|
||||||
console.log('1. Received payload:', payload);
|
|
||||||
console.log('2. Documents count:', documents.length);
|
|
||||||
|
|
||||||
let finalPayload: CreateMovementPayload | FormData;
|
let finalPayload: CreateMovementPayload | FormData;
|
||||||
|
|
||||||
if (documents.length > 0) {
|
if (documents.length > 0) {
|
||||||
console.log('3. Creating FormData (has documents)');
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('data', JSON.stringify(payload));
|
formData.append('data', JSON.stringify(payload));
|
||||||
documents.forEach((file, index) => {
|
documents.forEach((file, index) => {
|
||||||
formData.append(`documents[${index}]`, file);
|
formData.append(`documents[${index}]`, file);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('4. FormData entries:');
|
|
||||||
for (const [key, value] of formData.entries()) {
|
|
||||||
if (value instanceof File) {
|
|
||||||
console.log(
|
|
||||||
` ${key}: [File] ${value.name} (${value.size} bytes)`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.log(` ${key}: ${value}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
finalPayload = formData as unknown as CreateMovementPayload;
|
finalPayload = formData as unknown as CreateMovementPayload;
|
||||||
} else {
|
} else {
|
||||||
console.log('3. Sending as JSON (no documents)');
|
|
||||||
console.log('4. Payload:', JSON.stringify(payload, null, 2));
|
|
||||||
finalPayload = payload;
|
finalPayload = payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('=== END CREATE HANDLER DEBUG ===');
|
|
||||||
|
|
||||||
const res = await MovementApi.create(finalPayload);
|
const res = await MovementApi.create(finalPayload);
|
||||||
if (isResponseError(res)) {
|
if (isResponseError(res)) {
|
||||||
console.error('API Error:', res);
|
console.error('API Error:', res);
|
||||||
@@ -69,44 +49,22 @@ export const useMovementFormHandlers = (initialValuesId?: number) => {
|
|||||||
payload: UpdateMovementPayload,
|
payload: UpdateMovementPayload,
|
||||||
documents: File[] = []
|
documents: File[] = []
|
||||||
) => {
|
) => {
|
||||||
console.log('=== UPDATE HANDLER DEBUG ===');
|
|
||||||
console.log('1. Received payload:', payload);
|
|
||||||
console.log('2. Movement ID:', movementId);
|
|
||||||
console.log('3. Documents count:', documents.length);
|
|
||||||
|
|
||||||
let finalPayload: UpdateMovementPayload | FormData;
|
let finalPayload: UpdateMovementPayload | FormData;
|
||||||
|
|
||||||
if (documents.length > 0) {
|
if (documents.length > 0) {
|
||||||
console.log('4. Creating FormData (has documents)');
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('data', JSON.stringify(payload));
|
formData.append('data', JSON.stringify(payload));
|
||||||
documents.forEach((file, index) => {
|
documents.forEach((file, index) => {
|
||||||
formData.append(`documents[${index}]`, file);
|
formData.append(`documents[${index}]`, file);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('5. FormData entries:');
|
|
||||||
for (const [key, value] of formData.entries()) {
|
|
||||||
if (value instanceof File) {
|
|
||||||
console.log(
|
|
||||||
` ${key}: [File] ${value.name} (${value.size} bytes)`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.log(` ${key}: ${value}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
finalPayload = formData as unknown as UpdateMovementPayload;
|
finalPayload = formData as unknown as UpdateMovementPayload;
|
||||||
} else {
|
} else {
|
||||||
console.log('4. Sending as JSON (no documents)');
|
|
||||||
console.log('5. Payload:', JSON.stringify(payload, null, 2));
|
|
||||||
finalPayload = payload;
|
finalPayload = payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('=== END UPDATE HANDLER DEBUG ===');
|
|
||||||
|
|
||||||
const res = await MovementApi.update(movementId, finalPayload);
|
const res = await MovementApi.update(movementId, finalPayload);
|
||||||
if (res?.status === 'error') {
|
if (res?.status === 'error') {
|
||||||
console.error('API Error:', res);
|
|
||||||
setMovementFormErrorMessage(res.message);
|
setMovementFormErrorMessage(res.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ export async function httpClient<T, B = unknown>(
|
|||||||
(!opts.auth && opts.auth !== 'none' && opts.auth !== 'bearer');
|
(!opts.auth && opts.auth !== 'none' && opts.auth !== 'bearer');
|
||||||
const isBearerAuth = opts.auth === 'bearer' && !!opts.token;
|
const isBearerAuth = opts.auth === 'bearer' && !!opts.token;
|
||||||
|
|
||||||
|
const isFormData =
|
||||||
|
typeof FormData !== 'undefined' && opts.body instanceof FormData;
|
||||||
|
|
||||||
const config: AxiosRequestConfig = {
|
const config: AxiosRequestConfig = {
|
||||||
url: path,
|
url: path,
|
||||||
method: opts.method ?? 'GET',
|
method: opts.method ?? 'GET',
|
||||||
@@ -22,7 +25,7 @@ export async function httpClient<T, B = unknown>(
|
|||||||
timeout: opts.timeoutMs ?? 10_000,
|
timeout: opts.timeoutMs ?? 10_000,
|
||||||
withCredentials: isCookieAuth && !isBearerAuth,
|
withCredentials: isCookieAuth && !isBearerAuth,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
...(isFormData ? {} : { 'Content-Type': 'application/json' }),
|
||||||
...(opts.headers ?? {}),
|
...(opts.headers ?? {}),
|
||||||
...(isBearerAuth && !isCookieAuth
|
...(isBearerAuth && !isCookieAuth
|
||||||
? { Authorization: `Bearer ${opts.token}` }
|
? { Authorization: `Bearer ${opts.token}` }
|
||||||
|
|||||||
Reference in New Issue
Block a user