added punchout prefill is happening
This commit is contained in:
parent
32ddfff807
commit
45e1a2f82c
@ -17,7 +17,7 @@ import {
|
||||
WfLookupField,
|
||||
RadioField,
|
||||
} from './fields';
|
||||
import { ORDER_BOOKING, STORE } from '../../api/config';
|
||||
import { ORDER_BOOKING, STORE, DAILY_REPORTS } from '../../api/config';
|
||||
|
||||
export interface DynamicFormProps {
|
||||
client: ZinoClient;
|
||||
@ -51,7 +51,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
let mounted = true;
|
||||
setLoading(true);
|
||||
client.formSchema(currentActivityId, currentInstanceId)
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (mounted) {
|
||||
setSchema(res);
|
||||
const defaultValues: Record<string, unknown> = {};
|
||||
@ -140,6 +140,43 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
||||
if (!imageFieldIds.has(k)) defaultValues[k] = v;
|
||||
});
|
||||
}
|
||||
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'
|
||||
};
|
||||
headers['orgid'] = '57';
|
||||
headers['groupid'] = '25';
|
||||
|
||||
const summaryRes = await client.request<any>(
|
||||
'POST',
|
||||
'/api/papi2/productive-call-summary',
|
||||
{ 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);
|
||||
setLoading(false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user