Skip to content

Commit 02c2721

Browse files
committed
Profile update page with Inertia and Vue
1 parent 66010a3 commit 02c2721

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed

app/Http/Controllers/Admin/UserController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function accountInfo()
175175
*/
176176
public function accountInfoStore(Request $request)
177177
{
178-
$request->validate('account', [
178+
$request->validate([
179179
'name' => ['required', 'string', 'max:255'],
180180
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email,'.\Auth::user()->id],
181181
]);
@@ -188,7 +188,7 @@ public function accountInfoStore(Request $request)
188188
$message = 'Error while saving. Please try again.';
189189
}
190190

191-
return redirect()->route('admin.account.info')->with('account_message', __($message));
191+
return redirect()->route('admin.account.info')->with('message', __($message));
192192
}
193193

194194
/**
@@ -216,7 +216,7 @@ public function changePasswordStore(Request $request)
216216
$validator->validate();
217217

218218
$user = \Auth::user()->update([
219-
'password' => Hash::make($request->input('old_password')),
219+
'password' => Hash::make($request->input('new_password')),
220220
]);
221221

222222
if ($user) {
@@ -225,6 +225,6 @@ public function changePasswordStore(Request $request)
225225
$message = 'Error while saving. Please try again.';
226226
}
227227

228-
return redirect()->route('admin.account.info')->with('password_message', __($message));
228+
return redirect()->route('admin.account.info')->with('message', __($message));
229229
}
230230
}

resources/js/Pages/Admin/User/AccountInfo.vue

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
mdiAsterisk,
99
mdiFormTextboxPassword,
1010
mdiArrowLeftBoldOutline,
11+
mdiAlertBoxOutline,
1112
} from "@mdi/js";
1213
import SectionMain from "@/Components/SectionMain.vue";
1314
import CardBox from "@/Components/CardBox.vue";
@@ -16,7 +17,8 @@ import FormField from "@/Components/FormField.vue";
1617
import FormControl from "@/Components/FormControl.vue";
1718
import BaseButton from "@/Components/BaseButton.vue";
1819
import BaseButtons from "@/Components/BaseButtons.vue";
19-
import LayoutAuthenticated from "@/layouts/LayoutAuthenticated.vue";
20+
import NotificationBar from "@/Components/NotificationBar.vue";
21+
import LayoutAuthenticated from "@/Layouts/LayoutAuthenticated.vue";
2022
import SectionTitleLineWithButton from "@/Components/SectionTitleLineWithButton.vue";
2123
2224
const props = defineProps({
@@ -31,9 +33,9 @@ const profileForm = useForm({
3133
email: props.user.email,
3234
});
3335
const passwordForm = useForm({
34-
old_password: "",
35-
new_password: "",
36-
confirm_password: "",
36+
old_password: null,
37+
new_password: null,
38+
confirm_password: null,
3739
});
3840
</script>
3941

@@ -50,7 +52,13 @@ const passwordForm = useForm({
5052
small
5153
/>
5254
</SectionTitleLineWithButton>
53-
55+
<NotificationBar
56+
v-if="$page.props.flash.message"
57+
color="success"
58+
:icon="mdiAlertBoxOutline"
59+
>
60+
{{ $page.props.flash.message }}
61+
</NotificationBar>
5462
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
5563
<CardBox
5664
title="Edit Profile"
@@ -70,9 +78,9 @@ const passwordForm = useForm({
7078
required
7179
:error="profileForm.errors.name"
7280
>
73-
<div class="text-red-400 text-sm" v-if="profileForm.errors.name">
74-
{{ profileForm.errors.name }}
75-
</div>
81+
<div class="text-red-400 text-sm" v-if="profileForm.errors.name">
82+
{{ profileForm.errors.name }}
83+
</div>
7684
</FormControl>
7785
</FormField>
7886
<FormField
@@ -88,9 +96,9 @@ const passwordForm = useForm({
8896
required
8997
:error="profileForm.errors.email"
9098
>
91-
<div class="text-red-400 text-sm" v-if="profileForm.errors.email">
92-
{{ profileForm.errors.email }}
93-
</div>
99+
<div class="text-red-400 text-sm" v-if="profileForm.errors.email">
100+
{{ profileForm.errors.email }}
101+
</div>
94102
</FormControl>
95103
</FormField>
96104

@@ -106,7 +114,10 @@ const passwordForm = useForm({
106114
:icon="mdiLock"
107115
form
108116
@submit.prevent="
109-
passwordForm.post(route('admin.account.password.store'))
117+
passwordForm.post(route('admin.account.password.store'), {
118+
preserveScroll: true,
119+
onSuccess: () => passwordForm.reset(),
120+
})
110121
"
111122
>
112123
<FormField
@@ -122,9 +133,12 @@ const passwordForm = useForm({
122133
required
123134
:error="passwordForm.errors.old_password"
124135
>
125-
<div class="text-red-400 text-sm" v-if="passwordForm.errors.old_password">
126-
{{ passwordForm.errors.old_password }}
127-
</div>
136+
<div
137+
class="text-red-400 text-sm"
138+
v-if="passwordForm.errors.old_password"
139+
>
140+
{{ passwordForm.errors.old_password }}
141+
</div>
128142
</FormControl>
129143
</FormField>
130144

@@ -143,9 +157,12 @@ const passwordForm = useForm({
143157
required
144158
:error="passwordForm.errors.new_password"
145159
>
146-
<div class="text-red-400 text-sm" v-if="passwordForm.errors.new_password">
147-
{{ passwordForm.errors.new_password }}
148-
</div>
160+
<div
161+
class="text-red-400 text-sm"
162+
v-if="passwordForm.errors.new_password"
163+
>
164+
{{ passwordForm.errors.new_password }}
165+
</div>
149166
</FormControl>
150167
</FormField>
151168

@@ -162,9 +179,12 @@ const passwordForm = useForm({
162179
required
163180
:error="passwordForm.errors.confirm_password"
164181
>
165-
<div class="text-red-400 text-sm" v-if="passwordForm.errors.confirm_password">
166-
{{ passwordForm.errors.confirm_password }}
167-
</div>
182+
<div
183+
class="text-red-400 text-sm"
184+
v-if="passwordForm.errors.confirm_password"
185+
>
186+
{{ passwordForm.errors.confirm_password }}
187+
</div>
168188
</FormControl>
169189
</FormField>
170190

0 commit comments

Comments
 (0)