forked from mirrors/homebox
95ab14b866
* format readme * update logo * format html * add logo to docs * repository for document and document tokens * add attachments type and repository * autogenerate types via scripts * use autogenerated types * attachment type updates * add insured and quantity fields for items * implement HasID interface for entities * implement label updates for items * implement service update method * WIP item update client side actions * check err on attachment * finish types for basic items editor * remove unused var * house keeping
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { UseConfirmDialogReturn } from "@vueuse/core";
|
|
import { Ref } from "vue";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
type Store = UseConfirmDialogReturn<any, boolean, boolean> & {
|
|
text: Ref<string>;
|
|
setup: boolean;
|
|
};
|
|
|
|
const store: Partial<Store> = {
|
|
text: ref("Are you sure you want to delete this item? "),
|
|
setup: false,
|
|
};
|
|
|
|
/**
|
|
* This function is used to wrap the ModalConfirmation which is a "Singleton" component
|
|
* that is used to confirm actions. It's mounded once on the root of the page and reused
|
|
* for every confirmation action that is required.
|
|
*
|
|
* This is in an experimental phase of development and may have unknown or unexpected side effects.
|
|
*/
|
|
export function useConfirm(): Store {
|
|
if (!store.setup) {
|
|
store.setup = true;
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const { isRevealed, reveal, confirm, cancel } = useConfirmDialog<any, boolean, boolean>();
|
|
store.isRevealed = isRevealed;
|
|
store.reveal = reveal;
|
|
store.confirm = confirm;
|
|
store.cancel = cancel;
|
|
}
|
|
|
|
async function openDialog(msg: string) {
|
|
store.text.value = msg;
|
|
return await store.reveal();
|
|
}
|
|
|
|
return {
|
|
...(store as Store),
|
|
reveal: openDialog,
|
|
};
|
|
}
|