Skip to content

Commit 3612d30

Browse files
committed
Show loading spinner on Registration form submit button on clik
1 parent 29f4da5 commit 3612d30

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

vue/src/views/Register.vue

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,42 @@
4646

4747
<div>
4848
<button type="submit"
49-
class="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
49+
:disabled="loading"
50+
class="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
51+
:class="{'cursor-not-allowed': loading, 'hover:bg-indigo-500': loading}"
52+
>
5053
<span class="absolute left-0 inset-y-0 flex items-center pl-3">
5154
<LockClosedIcon class="h-5 w-5 text-indigo-500 group-hover:text-indigo-400" aria-hidden="true"/>
5255
</span>
56+
<svg
57+
v-if="loading"
58+
class="animate-spin -ml-1 mr-3 h-5 w-5 text-white"
59+
xmlns="http://www.w3.org/2000/svg"
60+
fill="none"
61+
viewBox="0 0 24 24"
62+
>
63+
<circle
64+
class="opacity-25"
65+
cx="12"
66+
cy="12"
67+
r="10"
68+
stroke="currentColor"
69+
stroke-width="4"
70+
></circle>
71+
<path
72+
class="opacity-75"
73+
fill="currentColor"
74+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
75+
></path>
76+
</svg>
5377
Sign up
5478
</button>
5579
</div>
5680
</form>
5781
</template>
5882

5983
<script setup>
84+
import {ref} from 'vue'
6085
import {LockClosedIcon} from '@heroicons/vue/solid'
6186
import store from "../store";
6287
import {useRouter} from "vue-router";
@@ -67,16 +92,22 @@ const user = {
6792
email: '',
6893
password: ''
6994
};
95+
const loading = ref(false);
7096
7197
function register(ev) {
7298
ev.preventDefault();
99+
loading.value = true
73100
store
74101
.dispatch('register', user)
75102
.then(() => {
103+
loading.value = false
76104
router.push({
77105
name: 'Dashboard'
78106
})
79107
})
108+
.catch(() =>{
109+
loading.value = false;
110+
})
80111
}
81112
82113
</script>

0 commit comments

Comments
 (0)