|
1 | 1 | <template> |
2 | | - <div class="container"></div> |
| 2 | + <div class="container"> |
| 3 | + <h1 class="text-primary">Add Customer</h1> |
| 4 | + <hr class="my-2" /> |
| 5 | + <form @submit.prevent="handleSubmit"> |
| 6 | + <div class="jumbotron my-3 p-4"> |
| 7 | + <h4>Customer Info</h4> |
| 8 | + <div class="form-group"> |
| 9 | + <label>First Name</label> |
| 10 | + <input |
| 11 | + required |
| 12 | + v-model="customer.firstName" |
| 13 | + type="text" |
| 14 | + class="form-control" |
| 15 | + placeholder="Enter Fisrt Name" |
| 16 | + /> |
| 17 | + </div> |
| 18 | + <div class="form-group"> |
| 19 | + <label>Last Name</label> |
| 20 | + <input |
| 21 | + required |
| 22 | + v-model="customer.lastName" |
| 23 | + type="text" |
| 24 | + class="form-control" |
| 25 | + placeholder="Enter Last Name" |
| 26 | + /> |
| 27 | + </div> |
| 28 | + </div> |
| 29 | + <div class="jumbotron my-3 p-4"> |
| 30 | + <h4>Customer Contact</h4> |
| 31 | + <div class="form-group"> |
| 32 | + <label>Email Address</label> |
| 33 | + <input |
| 34 | + required |
| 35 | + v-model="customer.email" |
| 36 | + type="email" |
| 37 | + class="form-control" |
| 38 | + placeholder="Enter Email Address" |
| 39 | + /> |
| 40 | + </div> |
| 41 | + <div class="form-group"> |
| 42 | + <label>Phone Number</label> |
| 43 | + <input |
| 44 | + required |
| 45 | + v-model="customer.phone" |
| 46 | + type="tel" |
| 47 | + class="form-control" |
| 48 | + placeholder="Enter Phone Number" |
| 49 | + /> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + <div class="jumbotron my-3 p-4"> |
| 53 | + <h4>Customer location</h4> |
| 54 | + <div class="form-group"> |
| 55 | + <label>Address</label> |
| 56 | + <input |
| 57 | + required |
| 58 | + v-model="customer.address" |
| 59 | + type="text" |
| 60 | + class="form-control" |
| 61 | + placeholder="Enter Full Address" |
| 62 | + /> |
| 63 | + </div> |
| 64 | + <div class="form-group"> |
| 65 | + <label>City</label> |
| 66 | + <input |
| 67 | + required |
| 68 | + v-model="customer.city" |
| 69 | + type="text" |
| 70 | + class="form-control" |
| 71 | + placeholder="Enter City" |
| 72 | + /> |
| 73 | + </div> |
| 74 | + <div class="form-group"> |
| 75 | + <label>State</label> |
| 76 | + <input |
| 77 | + v-model="customer.state" |
| 78 | + type="text" |
| 79 | + class="form-control" |
| 80 | + placeholder="Enter State" |
| 81 | + /> |
| 82 | + </div> |
| 83 | + <div class="text-center"> |
| 84 | + <button class="btn btn-success">{{ submitted ? 'Loading ...' : 'Submit' }}</button> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + </form> |
| 88 | + </div> |
3 | 89 | </template> |
4 | 90 |
|
5 | 91 | <script> |
6 | 92 | export default { |
7 | 93 | name: "AppAddPage", |
| 94 | + data() { |
| 95 | + return { |
| 96 | + customer: { |
| 97 | + firstName: "", |
| 98 | + lastName: "", |
| 99 | + email: "", |
| 100 | + phone: "", |
| 101 | + city: "", |
| 102 | + address: "", |
| 103 | + state: "", |
| 104 | + }, |
| 105 | + submitted: false, |
| 106 | + }; |
| 107 | + }, |
| 108 | + methods: { |
| 109 | + handleSubmit: async function () { |
| 110 | + this.submitted = true; |
| 111 | + if (!this.validateEmail(this.customer.email)) { |
| 112 | + return this.$store.dispatch("setAlert", { |
| 113 | + type: "Error", |
| 114 | + msg: "Please enter a valid Email Address", |
| 115 | + }); |
| 116 | + } |
| 117 | + const res = await this.$store.dispatch("addCustomer", this.customer); |
| 118 | + console.log(res, "FROM COMPONENT"); |
| 119 | + }, |
| 120 | + validateEmail(email) { |
| 121 | + const reg = new RegExp( |
| 122 | + /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ |
| 123 | + ); |
| 124 | + return reg.test(email); |
| 125 | + }, |
| 126 | + }, |
8 | 127 | }; |
9 | 128 | </script> |
10 | 129 |
|
|
0 commit comments