|
166 | 166 | class="q-ml-sm" |
167 | 167 | flat |
168 | 168 | dense |
169 | | - :disable="props.row.enabled" |
| 169 | + :disable=" |
| 170 | + props.row.enabled || props.row.hasActiveFiatSubscription |
| 171 | + " |
170 | 172 | > |
171 | 173 | <q-tooltip class="bg-indigo" :offset="[10, 10]"> |
172 | 174 | <span v-if="props.row.enabled"> |
173 | 175 | Destroy: you can only destroy a disabled instance. Please |
174 | 176 | disable it first. |
175 | 177 | </span> |
| 178 | + <span v-else-if="props.row.hasActiveFiatSubscription"> |
| 179 | + Please end the subscription from /subscriptions for this |
| 180 | + instance first |
| 181 | + </span> |
176 | 182 | <span v-else> |
177 | 183 | Destroy: destroying will delete your instance and every bit of |
178 | 184 | data.</span |
@@ -2318,13 +2324,22 @@ export default defineComponent({ |
2318 | 2324 | ) |
2319 | 2325 | }, |
2320 | 2326 | destroyInstance: function (id) { |
2321 | | - if (this.data.find(i => i.id === id)?.enabled) { |
| 2327 | + const instance = this.data.find(i => i.id === id) |
| 2328 | +
|
| 2329 | + if (instance?.enabled) { |
2322 | 2330 | return this.q.notify({ |
2323 | 2331 | message: |
2324 | 2332 | 'You can only destroy a disabled instance. Please disable it first.', |
2325 | 2333 | color: 'warning' |
2326 | 2334 | }) |
2327 | 2335 | } |
| 2336 | + if (instance?.hasActiveFiatSubscription) { |
| 2337 | + return this.q.notify({ |
| 2338 | + message: |
| 2339 | + 'Please end the subscription from /subscriptions for this instance first', |
| 2340 | + color: 'warning' |
| 2341 | + }) |
| 2342 | + } |
2328 | 2343 | this.confirm( |
2329 | 2344 | `Destroy ${id}`, |
2330 | 2345 | 'Are you sure you want to destroy?' + |
@@ -2487,12 +2502,37 @@ export default defineComponent({ |
2487 | 2502 | return false |
2488 | 2503 | } |
2489 | 2504 | }, |
| 2505 | + getActiveFiatSubscriptionInstanceIds(subscriptions = []) { |
| 2506 | + return new Set( |
| 2507 | + subscriptions |
| 2508 | + .filter(subscription => { |
| 2509 | + if (!subscription) { |
| 2510 | + return false |
| 2511 | + } |
| 2512 | +
|
| 2513 | + if (+subscription.ended_at) { |
| 2514 | + return false |
| 2515 | + } |
| 2516 | +
|
| 2517 | + return true |
| 2518 | + }) |
| 2519 | + .map(subscription => `${subscription.instance_id}`) |
| 2520 | + ) |
| 2521 | + }, |
2490 | 2522 | refreshState: async function () { |
2491 | 2523 | try { |
2492 | | - const {data} = await saas.getInstances() |
| 2524 | + const [{data: instancesData}, {data: subscriptionsData}] = |
| 2525 | + await Promise.all([saas.getInstances(), saas.getUserSubscriptions()]) |
2493 | 2526 |
|
2494 | 2527 | await this.serverStatus() |
2495 | | - const tableData = (data || []).map(i => saas.mapInstance(i)) |
| 2528 | + const activeFiatSubscriptionInstanceIds = |
| 2529 | + this.getActiveFiatSubscriptionInstanceIds(subscriptionsData || []) |
| 2530 | + const tableData = (instancesData || []).map(i => ({ |
| 2531 | + ...saas.mapInstance(i), |
| 2532 | + hasActiveFiatSubscription: activeFiatSubscriptionInstanceIds.has( |
| 2533 | + `${i.id}` |
| 2534 | + ) |
| 2535 | + })) |
2496 | 2536 |
|
2497 | 2537 | this.activityStats[0].value = tableData.length |
2498 | 2538 | this.activityStats[1].value = tableData.filter( |
|
0 commit comments