added store edit
This commit is contained in:
parent
e8bc418d02
commit
91979632ad
@ -73,13 +73,9 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const imageFieldIds = new Set(
|
|
||||||
res.fields.filter(f => f.data_type === 'image' || f.data_type === 'file').map(f => f.id)
|
|
||||||
);
|
|
||||||
|
|
||||||
const mapPrefillData = (sourceData: Record<string, unknown>) => {
|
const mapPrefillData = (sourceData: Record<string, unknown>) => {
|
||||||
res.fields.forEach(f => {
|
res.fields.forEach(f => {
|
||||||
if (imageFieldIds.has(f.id)) return;
|
|
||||||
|
|
||||||
const getBaseId = (id: string) => id.replace(/_\d+$/, '');
|
const getBaseId = (id: string) => id.replace(/_\d+$/, '');
|
||||||
|
|
||||||
@ -131,13 +127,13 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
|
|
||||||
if (customPrefillData) {
|
if (customPrefillData) {
|
||||||
Object.entries(customPrefillData).forEach(([k, v]) => {
|
Object.entries(customPrefillData).forEach(([k, v]) => {
|
||||||
if (!imageFieldIds.has(k)) defaultValues[k] = v;
|
defaultValues[k] = v;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chainedPrefillData) {
|
if (chainedPrefillData) {
|
||||||
Object.entries(chainedPrefillData).forEach(([k, v]) => {
|
Object.entries(chainedPrefillData).forEach(([k, v]) => {
|
||||||
if (!imageFieldIds.has(k)) defaultValues[k] = v;
|
defaultValues[k] = v;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (currentActivityId === DAILY_REPORTS.activities.PUNCH_OUT.uid) {
|
if (currentActivityId === DAILY_REPORTS.activities.PUNCH_OUT.uid) {
|
||||||
|
|||||||
@ -1,12 +1,20 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
import { APP_ID } from '../../../api/config';
|
||||||
|
import { orderBookingClient } from '../../../api/clients';
|
||||||
|
|
||||||
export function ImagePreview({ file }: { file: File }) {
|
export function ImagePreview({ file }: { file: any }) {
|
||||||
const [url, setUrl] = useState<string | null>(null);
|
const [url, setUrl] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const objectUrl = URL.createObjectURL(file);
|
if (file instanceof File) {
|
||||||
setUrl(objectUrl);
|
const objectUrl = URL.createObjectURL(file);
|
||||||
return () => URL.revokeObjectURL(objectUrl);
|
setUrl(objectUrl);
|
||||||
|
return () => URL.revokeObjectURL(objectUrl);
|
||||||
|
} else if (file && file.uuid) {
|
||||||
|
setUrl(`${orderBookingClient.baseUrl}/app/${APP_ID}/view/files/${file.uuid}/preview`);
|
||||||
|
} else if (typeof file === 'string' && file.startsWith('http')) {
|
||||||
|
setUrl(file);
|
||||||
|
}
|
||||||
}, [file]);
|
}, [file]);
|
||||||
|
|
||||||
if (!url) return null;
|
if (!url) return null;
|
||||||
@ -26,7 +34,7 @@ export function FileInput({
|
|||||||
value: File[] | undefined | null | unknown;
|
value: File[] | undefined | null | unknown;
|
||||||
onChange: (files: File[]) => void;
|
onChange: (files: File[]) => void;
|
||||||
}) {
|
}) {
|
||||||
const files = Array.isArray(value) ? value : (value instanceof File ? [value] : []);
|
const files = Array.isArray(value) ? value : (value ? [value] : []);
|
||||||
|
|
||||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
if (e.target.files && e.target.files.length > 0) {
|
if (e.target.files && e.target.files.length > 0) {
|
||||||
@ -68,7 +76,7 @@ export function FileInput({
|
|||||||
<ImagePreview file={file} />
|
<ImagePreview file={file} />
|
||||||
) : (
|
) : (
|
||||||
<div className="w-full h-full flex items-center justify-center p-2 text-xs text-center break-all overflow-hidden text-muted">
|
<div className="w-full h-full flex items-center justify-center p-2 text-xs text-center break-all overflow-hidden text-muted">
|
||||||
{file.name}
|
{file.name || file.original_name || 'File'}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<button
|
<button
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user