[READ-ONLY] Mirror of https://github.com/danielroe/dwaring87-webdev-wedding. Marissa & David's Wedding Website!
0

Configure Feed

Select the types of activity you want to include in your feed.

RSVP: only update changed guest properties

+28 -25
+16 -6
components/RSVP/Edit.vue
··· 21 21 22 22 const saving = ref(false); 23 23 const errors = ref([]); 24 - function save() { 24 + const save = async () => { 25 25 saving.value = true; 26 26 errors.value = []; 27 27 let guests = props.invitation.guests; 28 28 29 - guests.forEach(async (guest) => { 29 + for ( const guest of guests ) { 30 30 let id = guest.id; 31 - let container = document.getElementById(id); 31 + let container = document.getElementById(`guest-container-${id}`); 32 + 32 33 let name = container.getElementsByClassName('guest-name')[0].value; 33 34 let email = container.getElementsByClassName('guest-email')[0].value; 34 35 let rsvp_welcome = container.getElementsByClassName('guest-rsvp-welcome')[0].dataset.enabled === 'true'; ··· 41 42 } 42 43 let notes = container.getElementsByClassName('guest-notes')[0].value; 43 44 44 - let success = await updateGuest(id, name, email, rsvp_welcome, rsvp, transportation, diet, notes); 45 + let success = await updateGuest({ 46 + id, 47 + name: name !== guest.name ? name : undefined, 48 + email: email !== guest.email ? email : undefined, 49 + rsvp_welcome: rsvp_welcome !== guest.rsvp_welcome ? rsvp_welcome : undefined, 50 + rsvp: rsvp !== guest.rsvp ? rsvp : undefined, 51 + transportation: transportation !== guest.transportation ? transportation : undefined, 52 + diet: diet !== guest.diet ? diet : undefined, 53 + notes: notes !== guest.notes ? notes : undefined 54 + }); 45 55 if ( !success ) { 46 56 errors.value.push(`<strong>ERROR:</strong> Could not update Guest <em>${name}</em>. Please try again later.`); 47 57 } 48 - }); 58 + } 49 59 50 60 saving.value = false; 51 61 if ( !errors.value || errors.value.length === 0 ) { ··· 58 68 <div> 59 69 <h2>{{ invitation.name }}</h2> 60 70 61 - <div class="mx-4 mt-4 mb-8 px-4 bg-gray-100 border border-gray-400 rounded-md shadow" :id="guest.id" v-for="(guest, index) in invitation.guests" :key="guest.id"> 71 + <div class="mx-4 mt-4 mb-8 px-4 bg-gray-100 border border-gray-400 rounded-md shadow" :id="`guest-container-${guest.id}`" v-for="(guest) in invitation.guests" :key="guest.id"> 62 72 <div class="group"> 63 73 <p>Name:</p> 64 74 <input class="guest-name" :value="guest.name" />
+12 -19
composables/useCMS.ts
··· 124 124 125 125 /** 126 126 * Update the Guest Properties 127 - * @param id Guest ID 128 - * @param name Guest Name 129 - * @param email Guest Email 130 - * @param rsvp_welcome Guest RSVP to Welcome Dinner 131 - * @param rsvp Guest RSVP to Wedding 132 - * @param transportation Guest Transportation Interest 133 - * @param dietary_restrictions String of Guest's Dietary Restrictions 134 - * @param notes Guest Notes 127 + * @param guest The Guest to Update, with new properties set (id is required) 135 128 * @returns success flag 136 129 */ 137 - const updateGuest = async(id: string, name: string, email: string, rsvp_welcome: boolean, rsvp: boolean, transportation: boolean, dietary_restrictions: String[], notes: string): Promise<boolean> => { 130 + const updateGuest = async(guest: Guest): Promise<boolean> => { 138 131 try { 139 - const guest: Guest = { 140 - id, 141 - name, 142 - email, 143 - rsvp_welcome, 144 - rsvp, 145 - transportation, 146 - dietary_restrictions, 147 - notes 132 + if ( !guest || !guest.id ) { 133 + console.log("ERROR: Guest ID is required!"); 134 + return false; 148 135 } 136 + 137 + console.log("==> UPDATE GUEST:"); 138 + console.log(guest); 139 + return false; 140 + 149 141 await updateItem<Guest>({ 150 142 collection: "guests", 151 143 id: guest.id, 152 144 item: guest, 153 145 }); 154 146 return true; 155 - } catch (e) { 147 + } 148 + catch (e) { 156 149 console.log("ERROR: Could not update Guest!"); 157 150 console.log(e); 158 151 return false;