Files
homebox/frontend/components/App/ImportDialog.vue
Tonya d4e28e6f3b Upgrade frontend deps, including nuxt (#982)
* feat: begin upgrading deps, still very buggy

* feat: progress

* feat: sort all type issues

* fix: sort type issues

* fix: import sonner styles

* fix: nuxt is the enemy

* fix: try sorting issue with workflows

* fix: update vitest config for dynamic import of path and defineConfig

* fix: add missing import

* fix: add time out to try and fix issues

* fix: add ui:ci:preview task for frontend build in CI mode

* fix: i was silly

* feat: add go:ci:with-frontend task for CI mode and remove ui:ci:preview from e2e workflow

* fix: update baseURL in Playwright config for local testing to use port 7745

* fix: update E2E_BASE_URL and remove wait for timeout in login test for smoother execution
2025-09-04 09:00:25 +01:00

114 lines
3.1 KiB
Vue

<template>
<Dialog :dialog-id="DialogID.Import">
<DialogContent>
<DialogHeader>
<DialogTitle>{{ $t("components.app.import_dialog.title") }}</DialogTitle>
<DialogDescription> {{ $t("components.app.import_dialog.description") }} </DialogDescription>
</DialogHeader>
<div class="flex gap-2 rounded bg-destructive p-2 text-destructive-foreground shadow-lg">
<svg
xmlns="http://www.w3.org/2000/svg"
class="mb-auto size-6 shrink-0 stroke-current"
fill="none"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
/>
</svg>
<span class="text-sm">
{{ $t("components.app.import_dialog.change_warning") }}
</span>
</div>
<form class="flex flex-col gap-4" @submit.prevent="submitCsvFile">
<Input ref="importRef" type="file" accept=".csv,.tsv" @change="setFile" />
<DialogFooter>
<Button type="submit" :disabled="!importCsv"> {{ $t("global.submit") }} </Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
</template>
<script setup lang="ts">
import { useI18n } from "vue-i18n";
import { DialogID } from "@/components/ui/dialog-provider/utils";
import { toast } from "@/components/ui/sonner";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
type Props = {
modelValue?: boolean;
};
const { t } = useI18n();
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
});
const emit = defineEmits(["update:modelValue"]);
const dialog = useVModel(props, "modelValue", emit);
const api = useUserApi();
const importCsv = ref<File | undefined>(undefined);
const importLoading = ref(false);
const importRef = ref<HTMLInputElement>();
whenever(
() => !dialog.value,
() => {
importCsv.value = undefined;
}
);
function setFile(e: Event) {
const result = e.target as HTMLInputElement;
if (!result.files || result.files.length === 0) {
return;
}
importCsv.value = result.files[0];
}
async function submitCsvFile() {
if (!importCsv.value) {
toast.error(t("components.app.import_dialog.toast.please_select_file"));
return;
}
importLoading.value = true;
const { error } = await api.items.import(importCsv.value);
if (error) {
toast.error(t("components.app.import_dialog.toast.import_failed"));
}
// Reset
dialog.value = false;
importLoading.value = false;
importCsv.value = undefined;
if (importRef.value) {
importRef.value.value = "";
}
toast.success(t("components.app.import_dialog.toast.import_success"));
}
</script>