-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: reactive user updates in NavUser & fix password input focus in DeleteUser modal. #54
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent 👏
Thanks for the PR.
@chabdulrahmn and @tnylea, Adding File: // ...
import { ref, defineExpose } from 'vue';
// ...
// Create a reference to the native input element
const inputElement = ref<HTMLInputElement | null>(null);
// Expose the focus method
defineExpose({
focus: () => inputElement.value?.focus()
});
// ...
// And add a ref to the input element
<input ref="inputElement" v-model="modelValue" ... Then, in File: // Original
const passwordInput = ref<HTMLInputElement | null>(null);
// Updated
const passwordInput = ref<{ focus: () => void } | null>(null); With these changes, you can call |
@AaronLil, thanks for your input. I just tried this out, and everything is working fine. I do not see that it is breaking the build process. The files that are located inside of the We can incorporate this if the ShadCN vue library changes how they handle this. If you feel strongly that this should be handled differently, please open a new PR, and we can discuss it further. Appreciate it. |
Hi @tnylea, I recently started a brand new project using Laravel 12 with the Vue starter kit, and after merging this PR, I encountered the error shown in the image during the build process. That's why I left the comment. |
Thanks @AaronLil, looks like the latest version is using the Vue TSC prebuild step which is not included in this PR. taking a further look. |
@tnylea, |
@AaronLil. Perfect! Question though. In your screenshot, your |
@AaronLil, Thanks for your commits! On your question about After feedback, I’ve updated it to avoid Changes Made
Full Updated CodeFor reference, here’s the final result with all changes applied: <script setup lang="ts">
import { useForm } from '@inertiajs/vue3';
import { nextTick } from 'vue';
// Components
import HeadingSmall from '@/components/HeadingSmall.vue';
import InputError from '@/components/InputError.vue';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
const form = useForm({
password: '',
});
const deleteUser = (e: Event) => {
e.preventDefault();
form.delete(route('profile.destroy'), {
preserveScroll: true,
onSuccess: () => closeModal(),
onError: () => {
nextTick(() => {
const formElement = e.target as HTMLFormElement;
const passwordInput = formElement.password as HTMLInputElement;
passwordInput.focus();
});
},
onFinish: () => form.reset(),
});
};
const closeModal = () => {
form.clearErrors();
form.reset();
};
</script>
<template>
<div class="space-y-6">
<HeadingSmall title="Delete account" description="Delete your account and all of its resources" />
<div class="space-y-4 rounded-lg border border-red-100 bg-red-50 p-4 dark:border-red-200/10 dark:bg-red-700/10">
<div class="relative space-y-0.5 text-red-600 dark:text-red-100">
<p class="font-medium">Warning</p>
<p class="text-sm">Please proceed with caution, this cannot be undone.</p>
</div>
<Dialog>
<DialogTrigger as-child>
<Button variant="destructive">Delete account</Button>
</DialogTrigger>
<DialogContent>
<form class="space-y-6" @submit="deleteUser">
<DialogHeader class="space-y-3">
<DialogTitle>Are you sure you want to delete your account?</DialogTitle>
<DialogDescription>
Once your account is deleted, all of its resources and data will also be permanently deleted. Please enter your
password to confirm you would like to permanently delete your account.
</DialogDescription>
</DialogHeader>
<div class="grid gap-2">
<Label for="password" class="sr-only">Password</Label>
<Input id="password" type="password" name="password" v-model="form.password" placeholder="Password" />
<InputError :message="form.errors.password" />
</div>
<DialogFooter class="gap-2">
<DialogClose as-child>
<Button variant="secondary" @click="closeModal"> Cancel </Button>
</DialogClose>
<Button variant="destructive" :disabled="form.processing">
<button type="submit">Delete account</button>
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
</div>
</div>
</template> This grabs the Best, |
@chabdulrahmn, that looks fancy and worked like a charm! Now you can update this PR to use the code you provided so we can wrap up this issue. I ended up submitting another PR addressing the same problem, but I'll delete it as soon as your PR includes the new code. Great stuff, man! 🚀 |
This PR ensures the user info in NavUser updates reactively after a profile update and properly focuses the password input on error in the DeleteUser modal, improving the overall user experience.
Fix 1: Ensure user avatar & username update immediately in NavUser.vue after profile update.
const user = page.props.auth.user as User;
to
const user = computed(() => page.props.auth.user as User);
Fix 2: Properly focus password input on error in DeleteUser modal
TypeError: passwordInput.value?.focus is not a function
passwordInput.value?.$el?.focus()
instead ofpasswordInput.value?.focus()
<input>
inside theInput
component from shadcn-vue.