11<script setup lang="ts">
22import { mdiArrowLeft , mdiMicrosoftExcel , mdiSendCheck } from " @mdi/js" ;
3- import { ErrorMessages , getErrorMessages } from " ~/utils/errors" ;
3+ import { ErrorMessages } from " ~/utils/errors" ;
44import capitalize from " ~/utils/capitalize" ;
55
66definePageMeta ({
@@ -14,7 +14,8 @@ useHead({
1414const router = useRouter ();
1515const { mdAndUp, mdAndDown } = useDisplay ();
1616const authStore = useAuthStore ();
17- const billingStore = useBillingStore ();
17+ const notificationsStore = useNotificationsStore ();
18+ const { formatTimestamp } = useFilters ();
1819const { useApi } = useApiComposable ();
1920
2021const formFile = ref <File | null >(null );
@@ -24,6 +25,15 @@ const errorTitle = ref("");
2425const errorMessages = ref (new ErrorMessages ());
2526const bulkOrders = ref <any []>([]);
2627
28+ function parseErrors(error : any ): ErrorMessages {
29+ const bag = new ErrorMessages ();
30+ const data = error ?.data ?.data ;
31+ if (data && typeof data === " object" ) {
32+ Object .keys (data ).forEach ((key ) => bag .addMany (key , data [key ]));
33+ }
34+ return bag ;
35+ }
36+
2737function cleanName(requestId : string ): string {
2838 if (requestId .startsWith (" bulk-csv-" ))
2939 return requestId .replace (/ ^ bulk-csv-/ , " " ) + " .csv" ;
@@ -43,7 +53,10 @@ async function fetchBulkOrders() {
4353 });
4454 bulkOrders .value = response .data ?? [];
4555 } catch {
46- // silently fail
56+ notificationsStore .addNotification ({
57+ message: " Error while fetching bulk messages history" ,
58+ type: " error" ,
59+ });
4760 } finally {
4861 loadingHistory .value = false ;
4962 }
@@ -58,15 +71,26 @@ async function sendBulkMessages() {
5871 const api = useApi ();
5972 const formData = new FormData ();
6073 if (formFile .value ) formData .append (" document" , formFile .value );
61- await api (" /v1/bulk-messages" , { method: " POST" , body: formData });
74+ const response = await api <{ message? : string }>(" /v1/bulk-messages" , {
75+ method: " POST" ,
76+ body: formData ,
77+ });
78+ notificationsStore .addNotification ({
79+ message: response ?.message ?? " Bulk messages sent successfully" ,
80+ type: " success" ,
81+ });
6282 loading .value = false ;
6383 formFile .value = null ;
6484 fetchBulkOrders ();
6585 } catch (error : any ) {
6686 errorTitle .value = capitalize (
6787 error ?.data ?.message ?? " Error while sending bulk messages" ,
6888 );
69- errorMessages .value = getErrorMessages (error );
89+ errorMessages .value = parseErrors (error );
90+ notificationsStore .addNotification ({
91+ message: error ?.data ?.message ?? " Errors while sending bulk messages" ,
92+ type: " error" ,
93+ });
7094 loading .value = false ;
7195 }
7296}
@@ -97,7 +121,7 @@ onMounted(async () => {
97121 </VAppBar >
98122 <VContainer >
99123 <VRow >
100- <VCol cols="12">
124+ <VCol cols="12" md="10" offset-md="1" xxl="8" offset-xxl="2" >
101125 <h5 class =" text-headline-large mb-3 mt-3" >Bulk Messages</h5 >
102126 <p >
103127 Fill in our bulk SMS
@@ -142,11 +166,9 @@ onMounted(async () => {
142166 <VFileInput
143167 v-model =" formFile "
144168 label="File"
145- : prepend-icon = " undefined "
169+ color="primary "
146170 accept=".csv ,application/vnd.openxmlformats-officedocument .spreadsheetml .sheet "
147171 :error-messages =" errorMessages .get (' document' )"
148- persistent-placeholder
149- placeholder="Click here to upload your bulk SMS file."
150172 :append-inner-icon =" mdiMicrosoftExcel "
151173 variant="outlined"
152174 />
@@ -175,17 +197,17 @@ onMounted(async () => {
175197 </VCol >
176198 </VRow >
177199 <VRow class="mt-8">
178- <VCol cols="12">
200+ <VCol cols="12" md="10" offset-md="1" xxl="8" offset-xxl="2" >
179201 <h4 class =" text-headline-large mb-3" >Bulk Message History</h4 >
180202 <p class =" text-medium-emphasis" >
181203 Your 10 most recent bulk SMS uploads are shown below, including a
182204 delivery status breakdown for each batch. Click on a row to see
183205 individual messages on the search page.
184206 </p >
185207 <VProgressLinear v-if =" loadingHistory " indeterminate class="mb-4" />
186- <VTable v-else >
208+ <VTable density="comfortable" v-else >
187209 <thead >
188- <tr class =" text-uppercase text-title- medium" >
210+ <tr class =" text-uppercase text-medium-emphasis " >
189211 <th class =" text-left" >Name</th >
190212 <th class =" text-center" >Created At</th >
191213 <th class =" text-center" >Total</th >
@@ -208,7 +230,7 @@ onMounted(async () => {
208230 >
209231 <td class =" text-left" >{{ cleanName(order.request_id) }}</td >
210232 <td class =" text-center" >
211- {{ useFilters().timestamp (order.created_at) }}
233+ {{ formatTimestamp (order.created_at) }}
212234 </td >
213235 <td class =" text-center" >{{ order.total }}</td >
214236 <td class =" text-center" >{{ order.pending_count }}</td >
0 commit comments