Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Merge branch 'main' into feat/shadcn-admin-kit-v2

erwanMarmelabab73575267f8
diff --cc src/components/atomic-crm/dataImport/DataImportDialog.tsx
index 85900263,c5a33b23..c83f8813
--- a/src/components/atomic-crm/dataImport/DataImportDialog.tsx
+++ b/src/components/atomic-crm/dataImport/DataImportDialog.tsx
@@@ -70,42 -67,15 +67,15 @@@ export function DataImportDialog(
const sampleUrl = `data:text/csv;name=${sampleFileName(resource.name)};charset=utf-8,${encodeURIComponent(resource.sampleCsv)}`;
- useEffect(() => {
- if (importer.state === "complete") {
- refresh();
- }
- }, [importer.state, refresh]);
-
- const handleResourceChange = (name: string) => {
+ const handleResourceChange = (name: string | null) => {
const next = resources.find((candidate) => candidate.name === name);
if (!next) return;
- setFile(null);
- setResourceName(next.name);
- };
-
- const handleFileChange = (file: File | null) => {
- setFile(file);
+ onResourceChange(next.name);
};
- const startImport = () => {
+ const handleStart = () => {
if (!file) return;
- parseCsv(file);
- };
-
- const handleClose = () => {
- reset();
- setFile(null);
- onClose();
- };
-
- const handleReset = (e: MouseEvent<HTMLButtonElement>) => {
- e.preventDefault();
- reset();
+ onStart(file);
};
return (
@@@ -126,11 -96,6 +96,10 @@@
<Select
value={resource.name}
onValueChange={handleResourceChange}
- disabled={importer.state !== "idle"}
+ items={resources.map(({ name }) => ({
+ value: name,
+ label: getResourceLabel(name, 2),
+ }))}
>
<SelectTrigger id="data-import-resource" className="w-full">
<SelectValue />
@@@ -146,88 -111,25 +115,27 @@@
</div>
)}
- {importer.state === "running" && (
- <div className="flex flex-col gap-2">
- <Alert>
- <AlertDescription className="flex flex-row gap-4">
- <Loader2 className="h-5 w-5 animate-spin" />
- {translate("crm.data_import.running")}
- </AlertDescription>
- </Alert>
-
- <div className="text-sm">
- {translate("crm.data_import.progress", {
- importCount: importer.importCount,
- rowCount: importer.rowCount,
- errorCount: importer.errorCount,
- })}
- {importer.remainingTime !== null && (
- <>
- {" "}
- {translate("crm.data_import.remaining_time")}{" "}
- <strong>
- {millisecondsToTime(importer.remainingTime)}
- </strong>
- .{" "}
- <button
- onClick={handleReset}
- className="text-red-600 underline hover:text-red-800"
- >
- {translate("crm.data_import.stop")}
- </button>
- </>
- )}
- </div>
- </div>
- )}
-
- {importer.state === "error" && (
- <Alert variant="destructive">
- <AlertDescription>
- {translate("crm.data_import.error")}
- </AlertDescription>
- </Alert>
- )}
-
- {importer.state === "complete" && (
- <Alert>
- <AlertDescription>
- {translate("crm.data_import.complete", {
- importCount: importer.importCount,
- errorCount: importer.errorCount,
- })}
- </AlertDescription>
- </Alert>
- )}
-
- {importer.state === "idle" && (
- <>
- <Alert>
- <AlertDescription className="flex flex-col gap-4">
- {translate("crm.data_import.sample_hint")}
- <Link
- to={sampleUrl}
- download={sampleFileName(resource.name)}
- className={buttonVariants({
- variant: "outline",
- size: "sm",
- })}
- >
- {translate("crm.data_import.sample_download")}
- </Link>
- </AlertDescription>
- </Alert>
-
- <FileInput
- source="csv"
- label="crm.data_import.csv_file"
- accept={{ "text/csv": [".csv"] }}
- onChange={handleFileChange}
+ <Alert>
+ <AlertDescription className="flex flex-col gap-4">
+ {translate("crm.data_import.sample_hint")}
- <Button asChild variant="outline" size="sm">
- <Link to={sampleUrl} download={sampleFileName(resource.name)}>
- {translate("crm.data_import.sample_download")}
- </Link>
- </Button>
++ <Link
++ to={sampleUrl}
++ download={sampleFileName(resource.name)}
++ className={buttonVariants({ variant: "outline", size: "sm" })}
+ >
- <FileField source="src" title="title" target="_blank" />
- </FileInput>
- </>
- )}
++ {translate("crm.data_import.sample_download")}
++ </Link>
+ </AlertDescription>
+ </Alert>
+
+ <FileInput
+ source="csv"
+ label="crm.data_import.csv_file"
+ accept={{ "text/csv": [".csv"] }}
+ onChange={setFile}
+ >
+ <FileField source="src" title="title" target="_blank" />
+ </FileInput>
</div>
</Form>