mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
fix: check if slug is empty to show alert
This commit is contained in:
parent
a0dcec6e15
commit
3726dfd92e
1 changed files with 16 additions and 0 deletions
|
@ -46,6 +46,7 @@ import type { AxiosResponse } from "axios";
|
|||
import { useUserApi } from "~/composables/api";
|
||||
import { validators } from "~/composables/use-validators";
|
||||
import type { VForm } from "~/types/auto-forms";
|
||||
import { alert } from "~/composables/use-toast";
|
||||
|
||||
export default defineNuxtComponent({
|
||||
setup() {
|
||||
|
@ -59,6 +60,7 @@ export default defineNuxtComponent({
|
|||
|
||||
const api = useUserApi();
|
||||
const router = useRouter();
|
||||
const i18n = useI18n();
|
||||
|
||||
function handleResponse(response: AxiosResponse<string> | null, edit = false) {
|
||||
if (response?.status !== 201) {
|
||||
|
@ -71,11 +73,25 @@ export default defineNuxtComponent({
|
|||
|
||||
const newRecipeName = ref("");
|
||||
const domCreateByName = ref<VForm | null>(null);
|
||||
function createRecipeSlug(str: string): string {
|
||||
return str
|
||||
.toLowerCase()
|
||||
.normalize("NFD")
|
||||
.replace(/\p{Diacritic}/gu, "")
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.replace(/-+/g, "-");
|
||||
}
|
||||
|
||||
async function createByName(name: string) {
|
||||
if (!domCreateByName.value?.validate() || name === "") {
|
||||
return;
|
||||
}
|
||||
const recipeSlug = createRecipeSlug(name);
|
||||
if (!recipeSlug) {
|
||||
alert.error(i18n.t("recipe.recipe-creation-failed") as string);
|
||||
return;
|
||||
}
|
||||
const { response } = await api.recipes.createOne({ name });
|
||||
handleResponse(response as any, true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue