| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <div> | 
					
						
							|  |  |  |     <v-card-text> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       <v-switch | 
					
						
							|  |  |  |         v-model="webhookCopy.enabled" | 
					
						
							|  |  |  |         color="primary" | 
					
						
							|  |  |  |         :label="$t('general.enabled')" | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <v-text-field | 
					
						
							|  |  |  |         v-model="webhookCopy.name" | 
					
						
							|  |  |  |         :label="$t('settings.webhooks.webhook-name')" | 
					
						
							|  |  |  |         variant="underlined" | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <v-text-field | 
					
						
							|  |  |  |         v-model="webhookCopy.url" | 
					
						
							|  |  |  |         :label="$t('settings.webhooks.webhook-url')" | 
					
						
							|  |  |  |         variant="underlined" | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <v-time-picker | 
					
						
							|  |  |  |         v-model="scheduledTime" | 
					
						
							|  |  |  |         class="elevation-2" | 
					
						
							|  |  |  |         ampm-in-title | 
					
						
							|  |  |  |         format="ampm" | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  |     </v-card-text> | 
					
						
							|  |  |  |     <v-card-actions class="py-0 justify-end"> | 
					
						
							|  |  |  |       <BaseButtonGroup | 
					
						
							|  |  |  |         :buttons="[ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             icon: $globals.icons.delete, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             text: $t('general.delete'), | 
					
						
							| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  |             event: 'delete', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             icon: $globals.icons.testTube, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             text: $t('general.test'), | 
					
						
							| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  |             event: 'test', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             icon: $globals.icons.save, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             text: $t('general.save'), | 
					
						
							| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  |             event: 'save', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ]" | 
					
						
							|  |  |  |         @delete="$emit('delete', webhookCopy.id)" | 
					
						
							|  |  |  |         @save="handleSave" | 
					
						
							|  |  |  |         @test="$emit('test', webhookCopy.id)" | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |     </v-card-actions> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | import type { ReadWebhook } from "~/lib/api/types/household"; | 
					
						
							| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  | import { timeLocalToUTC, timeUTCToLocal } from "~/composables/use-group-webhooks"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | export default defineNuxtComponent({ | 
					
						
							| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  |   props: { | 
					
						
							|  |  |  |     webhook: { | 
					
						
							|  |  |  |       type: Object as () => ReadWebhook, | 
					
						
							|  |  |  |       required: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   emits: ["delete", "save", "test"], | 
					
						
							|  |  |  |   setup(props, { emit }) { | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const i18n = useI18n(); | 
					
						
							| 
									
										
										
										
											2022-06-19 11:47:16 -08:00
										 |  |  |     const itemUTC = ref<string>(props.webhook.scheduledTime); | 
					
						
							|  |  |  |     const itemLocal = ref<string>(timeUTCToLocal(props.webhook.scheduledTime)); | 
					
						
							| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const scheduledTime = computed({ | 
					
						
							|  |  |  |       get() { | 
					
						
							|  |  |  |         return itemLocal.value; | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2022-06-20 16:48:39 -08:00
										 |  |  |       set(v: string) { | 
					
						
							| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  |         itemUTC.value = timeLocalToUTC(v); | 
					
						
							|  |  |  |         itemLocal.value = v; | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const webhookCopy = ref({ ...props.webhook }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function handleSave() { | 
					
						
							|  |  |  |       webhookCopy.value.scheduledTime = itemLocal.value; | 
					
						
							|  |  |  |       emit("save", webhookCopy.value); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     // Set page title using useSeoMeta
 | 
					
						
							|  |  |  |     useSeoMeta({ | 
					
						
							|  |  |  |       title: i18n.t("settings.webhooks.webhooks"), | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-17 13:25:47 -08:00
										 |  |  |     return { | 
					
						
							|  |  |  |       webhookCopy, | 
					
						
							|  |  |  |       scheduledTime, | 
					
						
							|  |  |  |       handleSave, | 
					
						
							|  |  |  |       itemUTC, | 
					
						
							|  |  |  |       itemLocal, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | </script> |