added the work pre punchout prefill
This commit is contained in:
parent
8ad60001fe
commit
0ab9be85a6
@ -217,6 +217,7 @@ export const SALES_REPORT_SO_NAMES = [
|
|||||||
export const PIPELINE = {
|
export const PIPELINE = {
|
||||||
endpoints: {
|
endpoints: {
|
||||||
nearestStores: '/api/papi2/nearest-stores',
|
nearestStores: '/api/papi2/nearest-stores',
|
||||||
dailySalesReport: '/api/papi2/daily-sales-report'
|
dailySalesReport: '/api/papi2/daily-sales-report',
|
||||||
|
productiveCallSummary: '/api/papi2/productive-call-summary'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import {
|
|||||||
WfLookupField,
|
WfLookupField,
|
||||||
RadioField,
|
RadioField,
|
||||||
} from './fields';
|
} from './fields';
|
||||||
import { ORDER_BOOKING, STORE } from '../../api/config';
|
import { ORDER_BOOKING, STORE, DAILY_REPORTS, PIPELINE } from '../../api/config';
|
||||||
|
|
||||||
export interface DynamicFormProps {
|
export interface DynamicFormProps {
|
||||||
client: ZinoClient;
|
client: ZinoClient;
|
||||||
@ -52,7 +52,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
let mounted = true;
|
let mounted = true;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
client.formSchema(currentActivityId, currentInstanceId)
|
client.formSchema(currentActivityId, currentInstanceId)
|
||||||
.then(res => {
|
.then(async (res) => {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setSchema(res);
|
setSchema(res);
|
||||||
const defaultValues: Record<string, unknown> = {};
|
const defaultValues: Record<string, unknown> = {};
|
||||||
@ -78,15 +78,54 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
res.fields.filter(f => f.data_type === 'image' || f.data_type === 'file').map(f => f.id)
|
res.fields.filter(f => f.data_type === 'image' || f.data_type === 'file').map(f => f.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const mapPrefillData = (sourceData: Record<string, unknown>) => {
|
||||||
|
res.fields.forEach(f => {
|
||||||
|
if (imageFieldIds.has(f.id)) return;
|
||||||
|
|
||||||
|
const getBaseId = (id: string) => id.replace(/_\d+$/, '');
|
||||||
|
|
||||||
|
if (sourceData[f.id] !== undefined) {
|
||||||
|
defaultValues[f.id] = sourceData[f.id];
|
||||||
|
} else if (f.mapped_workflow_field && sourceData[f.mapped_workflow_field] !== undefined) {
|
||||||
|
defaultValues[f.id] = sourceData[f.mapped_workflow_field];
|
||||||
|
} else if (sourceData[getBaseId(f.id)] !== undefined) {
|
||||||
|
defaultValues[f.id] = sourceData[getBaseId(f.id)];
|
||||||
|
} else {
|
||||||
|
const matchingDataKey = Object.keys(sourceData).find(k => getBaseId(k) === f.id || getBaseId(k) === getBaseId(f.id) || k === f.mapped_workflow_field);
|
||||||
|
if (matchingDataKey) {
|
||||||
|
defaultValues[f.id] = sourceData[matchingDataKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f.data_type === 'grid' && Array.isArray(defaultValues[f.id])) {
|
||||||
|
defaultValues[f.id] = (defaultValues[f.id] as Record<string, unknown>[]).map(row => {
|
||||||
|
const newRow: Record<string, unknown> = { ...row };
|
||||||
|
f.columns?.forEach(col => {
|
||||||
|
const colBaseId = getBaseId(col.id);
|
||||||
|
if (row[col.id] !== undefined) {
|
||||||
|
newRow[col.id] = row[col.id];
|
||||||
|
} else if (col.mapped_workflow_field && row[col.mapped_workflow_field] !== undefined) {
|
||||||
|
newRow[col.id] = row[col.mapped_workflow_field];
|
||||||
|
} else if (row[colBaseId] !== undefined) {
|
||||||
|
newRow[col.id] = row[colBaseId];
|
||||||
|
} else {
|
||||||
|
const matchingRowKey = Object.keys(row).find(k => getBaseId(k) === col.id || getBaseId(k) === colBaseId || k === col.mapped_workflow_field);
|
||||||
|
if (matchingRowKey) {
|
||||||
|
newRow[col.id] = row[matchingRowKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return newRow;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (!ignorePrefill) {
|
if (!ignorePrefill) {
|
||||||
if (res.prefill_data) {
|
if (res.prefill_data && Object.keys(res.prefill_data).length > 0) {
|
||||||
Object.entries(res.prefill_data).forEach(([k, v]) => {
|
mapPrefillData(res.prefill_data);
|
||||||
if (!imageFieldIds.has(k)) defaultValues[k] = v;
|
|
||||||
});
|
|
||||||
} else if (res.data) {
|
} else if (res.data) {
|
||||||
Object.entries(res.data).forEach(([k, v]) => {
|
mapPrefillData(res.data);
|
||||||
if (!imageFieldIds.has(k)) defaultValues[k] = v;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +141,44 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentActivityId === DAILY_REPORTS.activities.PUNCH_OUT.uid) {
|
||||||
|
const user = client.currentUser();
|
||||||
|
const userEmail = user?.email;
|
||||||
|
if (userEmail) {
|
||||||
|
try {
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
'templateid': '192',
|
||||||
|
'x-pipeline-version': 'draft',
|
||||||
|
'orgid': '57',
|
||||||
|
'groupid': '25'
|
||||||
|
};
|
||||||
|
|
||||||
|
const summaryRes = await client.request<any>(
|
||||||
|
'POST',
|
||||||
|
PIPELINE.endpoints.productiveCallSummary,
|
||||||
|
{ email: userEmail },
|
||||||
|
headers
|
||||||
|
);
|
||||||
|
let summaryData = summaryRes.data || summaryRes;
|
||||||
|
if (Array.isArray(summaryData)) {
|
||||||
|
summaryData = summaryData[0] || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map the API response keys to match the form field keys
|
||||||
|
if (summaryData.productive_call !== undefined) {
|
||||||
|
summaryData.total_productive_calls = summaryData.productive_call;
|
||||||
|
}
|
||||||
|
if (summaryData.non_productive_call !== undefined) {
|
||||||
|
summaryData.total_non_productive_calls = summaryData.non_productive_call;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapPrefillData(summaryData);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Failed to load productive call summary', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setValues(defaultValues);
|
setValues(defaultValues);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
if (res.activity_name) {
|
if (res.activity_name) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user