5959 <v-card-text class =" pa-4" >
6060 <v-list lines =" one" border class =" rounded-lg mb-4" >
6161 <v-list-item v-for =" h in households" :key =" h.id" :title =" h.name" >
62+ <template v-slot :subtitle v-if =" currentHousehold ?.id === h .id " >
63+ <span class =" text-success font-weight-bold text-caption" >Currently Active</span >
64+ </template >
65+
6266 <template v-slot :append >
63- <v-chip v-if =" currentHousehold?.id === h.id" size =" x-small" color =" success" >
64- Active
65- </v-chip >
67+ <v-btn
68+ v-if =" currentHousehold?.id !== h.id"
69+ size =" small"
70+ variant =" text"
71+ color =" primary"
72+ @click =" switchHousehold(h)"
73+ >Switch</v-btn
74+ >
75+
76+ <v-btn
77+ icon =" mdi-delete"
78+ size =" small"
79+ variant =" text"
80+ color =" grey"
81+ class =" ml-2"
82+ @click =" confirmDeleteHousehold(h)"
83+ ></v-btn >
6684 </template >
6785 </v-list-item >
6886 </v-list >
87+
6988 <div class =" d-flex" >
7089 <v-text-field
7190 v-model =" newHouseholdName"
72- label =" Name"
91+ label =" New Household Name"
7392 variant =" outlined"
7493 density =" compact"
7594 hide-details
7695 class =" mr-2"
77- / >
96+ ></ v-text-field >
7897 <v-btn
7998 color =" primary"
8099 height =" 40"
81100 @click =" createHousehold(false)"
82101 :loading =" creatingHousehold"
102+ >Add</v-btn
83103 >
84- Add
85- </v-btn >
86104 </div >
87105 </v-card-text >
106+ <v-card-actions
107+ ><v-spacer ></v-spacer
108+ ><v-btn variant =" text" @click =" manageDialog = false" >Close</v-btn ></v-card-actions
109+ >
110+ </v-card >
111+ </v-dialog >
112+
113+ <v-dialog v-model =" deleteHouseholdDialog" max-width =" 400px" >
114+ <v-card >
115+ <v-card-title class =" text-h5 text-red" >Delete Household?</v-card-title >
116+ <v-card-text >
117+ Are you sure you want to delete <strong >{{ householdToDelete?.name }}</strong
118+ >? <br /><br />
119+ <v-alert type =" warning" variant =" tonal" density =" compact" border =" start" >
120+ This will permanently delete all
121+ <strong >Policies, Assets, and Documents</strong > associated with this household.
122+ </v-alert >
123+ </v-card-text >
88124 <v-card-actions >
89- <v-spacer />
90- <v-btn variant =" text" @click =" manageDialog = false" > Close </v-btn >
125+ <v-spacer ></v-spacer >
126+ <v-btn color =" grey" variant =" text" @click =" deleteHouseholdDialog = false" >Cancel</v-btn >
127+ <v-btn
128+ color =" red"
129+ variant =" flat"
130+ @click =" executeDeleteHousehold"
131+ :loading =" deletingHousehold"
132+ >Delete Forever</v-btn
133+ >
91134 </v-card-actions >
92135 </v-card >
93136 </v-dialog >
@@ -107,8 +150,11 @@ export default {
107150 creatingHousehold: false ,
108151 currencyCode: ' GBP' ,
109152 currentHousehold: null ,
153+ deleteHouseholdDialog: false ,
154+ deletingHousehold: false ,
110155 drawer: null ,
111156 households: [],
157+ householdToDelete: null ,
112158 initialized: false ,
113159 manageDialog: false ,
114160 newHouseholdName: ' ' ,
@@ -153,6 +199,36 @@ export default {
153199 },
154200 switchHousehold (household ) {
155201 this .currentHousehold = household
202+ this .manageDialog = false
203+ },
204+ confirmDeleteHousehold (household ) {
205+ this .householdToDelete = household
206+ this .deleteHouseholdDialog = true
207+ },
208+ async executeDeleteHousehold () {
209+ if (! this .householdToDelete ) return
210+ this .deletingHousehold = true
211+ try {
212+ await axios .delete (` http://localhost:8000/households/${ this .householdToDelete .id } ` )
213+ this .households = this .households .filter ((h ) => h .id !== this .householdToDelete .id )
214+ if (this .currentHousehold && this .currentHousehold .id === this .householdToDelete .id ) {
215+ if (this .households .length > 0 ) {
216+ this .switchHousehold (this .households [0 ])
217+ } else {
218+ this .currentHousehold = null
219+ this .showOnboarding = true
220+ this .manageDialog = false
221+ }
222+ }
223+
224+ this .deleteHouseholdDialog = false
225+ this .householdToDelete = null
226+ } catch (e) {
227+ console .error (' Failed to delete household' , e)
228+ alert (' Could not delete household. Ensure all policies are removed or try again.' )
229+ } finally {
230+ this .deletingHousehold = false
231+ }
156232 },
157233 async createHousehold (isOnboarding ) {
158234 if (! this .newHouseholdName ) return
0 commit comments