mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +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,
|
||||
enableReinitialize: true,
|
||||
onSubmit: async (values) => {
|
||||
console.log('=== FORM SUBMIT DEBUG ===');
|
||||
console.log('1. Form values received:', values);
|
||||
|
||||
setMovementFormErrorMessage('');
|
||||
const documents: File[] = [];
|
||||
const deliveriesPayload = values.deliveries.map((d, idx) => {
|
||||
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) {
|
||||
documents.push(d.document);
|
||||
documentIndex = documents.length - 1;
|
||||
console.log(` → Document added at index ${documentIndex}`);
|
||||
} else {
|
||||
console.log(` → No document for delivery ${idx}, using index 0`);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -117,21 +105,6 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
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) {
|
||||
case 'add':
|
||||
await createMovementHandler(payload, documents);
|
||||
|
||||
@@ -17,40 +17,20 @@ export const useMovementFormHandlers = (initialValuesId?: number) => {
|
||||
|
||||
const createMovementHandler = useCallback(
|
||||
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;
|
||||
|
||||
if (documents.length > 0) {
|
||||
console.log('3. Creating FormData (has documents)');
|
||||
const formData = new FormData();
|
||||
formData.append('data', JSON.stringify(payload));
|
||||
documents.forEach((file, index) => {
|
||||
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;
|
||||
} else {
|
||||
console.log('3. Sending as JSON (no documents)');
|
||||
console.log('4. Payload:', JSON.stringify(payload, null, 2));
|
||||
finalPayload = payload;
|
||||
}
|
||||
|
||||
console.log('=== END CREATE HANDLER DEBUG ===');
|
||||
|
||||
const res = await MovementApi.create(finalPayload);
|
||||
if (isResponseError(res)) {
|
||||
console.error('API Error:', res);
|
||||
@@ -69,44 +49,22 @@ export const useMovementFormHandlers = (initialValuesId?: number) => {
|
||||
payload: UpdateMovementPayload,
|
||||
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;
|
||||
|
||||
if (documents.length > 0) {
|
||||
console.log('4. Creating FormData (has documents)');
|
||||
const formData = new FormData();
|
||||
formData.append('data', JSON.stringify(payload));
|
||||
documents.forEach((file, index) => {
|
||||
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;
|
||||
} else {
|
||||
console.log('4. Sending as JSON (no documents)');
|
||||
console.log('5. Payload:', JSON.stringify(payload, null, 2));
|
||||
finalPayload = payload;
|
||||
}
|
||||
|
||||
console.log('=== END UPDATE HANDLER DEBUG ===');
|
||||
|
||||
const res = await MovementApi.update(movementId, finalPayload);
|
||||
if (res?.status === 'error') {
|
||||
console.error('API Error:', res);
|
||||
setMovementFormErrorMessage(res.message);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ export async function httpClient<T, B = unknown>(
|
||||
(!opts.auth && opts.auth !== 'none' && opts.auth !== 'bearer');
|
||||
const isBearerAuth = opts.auth === 'bearer' && !!opts.token;
|
||||
|
||||
const isFormData =
|
||||
typeof FormData !== 'undefined' && opts.body instanceof FormData;
|
||||
|
||||
const config: AxiosRequestConfig = {
|
||||
url: path,
|
||||
method: opts.method ?? 'GET',
|
||||
@@ -22,7 +25,7 @@ export async function httpClient<T, B = unknown>(
|
||||
timeout: opts.timeoutMs ?? 10_000,
|
||||
withCredentials: isCookieAuth && !isBearerAuth,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(isFormData ? {} : { 'Content-Type': 'application/json' }),
|
||||
...(opts.headers ?? {}),
|
||||
...(isBearerAuth && !isCookieAuth
|
||||
? { Authorization: `Bearer ${opts.token}` }
|
||||
|
||||
Reference in New Issue
Block a user