Skip to content

Commit 07115d4

Browse files
authored
Merge pull request #8 from devforth/adjust-import-dialog
Adjust import dialog
2 parents 933788c + fdc5523 commit 07115d4

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

custom/ImportCsv.vue

+37-17
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,35 @@
55
<svg v-if="inProgress"
66
aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
77
</div>
8-
<Dialog ref="confirmDialog"
9-
:header="t('Import Confirmation')"
10-
:buttons="[
11-
{ label: t('Import & Replace'), onclick: (dialog) => { confirmImport(dialog) } },
12-
{ label: t('Import New Only'), onclick: (dialog) => { confirmImportNewOnly(dialog) } },
13-
{ label: t('Cancel'), onclick: (dialog) => dialog.hide() }
14-
]"
15-
>
8+
<Dialog ref="confirmDialog" :header="t('Import Confirmation')" :buttons="computedButtons">
169
<div v-if="importStats">
17-
<p>{{ $t('Are you sure you want to continue?') }}</p>
18-
<p class="mt-2">{{ $t('You are importing {count} records:', { count: importStats.total }) }}</p>
19-
<ul class="list-disc ml-6 mt-2">
20-
<li>{{ $t('{count} existing records will be replaced (old records will be lost)', { count: importStats.existingCount }) }}</li>
21-
<li>{{ $t('{count} new records will be added', { count: importStats.newCount }) }}</li>
22-
</ul>
10+
<template v-if="importStats.existingCount > 0 && importStats.newCount > 0">
11+
<p>{{ $t('Are you sure you want to continue?') }}</p>
12+
<p class="mt-2">{{ $t('You are importing {count} records:', { count: importStats.total }) }}</p>
13+
<ul class="list-disc ml-6 mt-2">
14+
<li>{{ $t('{count} existing records will be replaced (old records will be lost)', { count: importStats.existingCount }) }}</li>
15+
<li>{{ $t('{count} new records will be added', { count: importStats.newCount }) }}</li>
16+
</ul>
17+
<p>{{ $t('What would you like to do?') }}</p>
18+
</template>
19+
20+
<template v-if="importStats.existingCount === 0 && importStats.newCount > 0">
21+
<p>{{ $t('Are you sure you want to import the new records?') }}</p>
22+
<p class="mt-2">{{ $t('You are about to import {count} new records.', { count: importStats.newCount }) }}</p>
23+
<p>{{ $t('Would you like to proceed?') }}</p>
24+
</template>
25+
26+
<template v-if="importStats.existingCount > 0 && importStats.newCount === 0">
27+
<p>{{ $t('Warning! All {count} records already exist in the system.', { count: importStats.existingCount }) }}</p>
28+
<p>{{ $t('Importing these will replace the existing records, which cannot be undone.') }}</p>
29+
<p>{{ $t('Would you like to proceed?') }}</p>
30+
</template>
2331
</div>
24-
</Dialog>
32+
</Dialog>
2533
</template>
2634

2735
<script setup lang="ts">
28-
import { ref, Ref } from 'vue';
36+
import { ref, Ref, computed } from 'vue';
2937
import { callAdminForthApi } from '@/utils';
3038
import adminforth from '@/adminforth';
3139
import Papa from 'papaparse';
@@ -42,7 +50,19 @@ const props = defineProps({
4250
meta: Object,
4351
record: Object,
4452
});
45-
53+
const computedButtons = computed(() => {
54+
if (!importStats.value) return [];
55+
56+
const buttons = [
57+
{ label: t('⚠️ Import All — Replace & Overwrite'), onclick: (dialog) => { confirmImport(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount > 0 },
58+
{ label: t('⚠️ Replace Existing Records'), onclick: (dialog) => { confirmImport(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount === 0 },
59+
{ label: t('➕ Import New Only'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount > 0 && importStats.value.newCount > 0 },
60+
{ label: t('➕ Import Records'), onclick: (dialog) => { confirmImportNewOnly(dialog) }, visible: importStats.value.existingCount === 0 && importStats.value.newCount > 0 },
61+
{ label: t('✖ Cancel'), onclick: (dialog) => dialog.hide() }
62+
];
63+
64+
return buttons.filter(button => button.visible !== false);
65+
});
4666
async function confirmImport(dialog) {
4767
dialog.hide();
4868
await postData(pendingData.value);

0 commit comments

Comments
 (0)