|
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 |
@@ -2301,13 +2307,22 @@ export default defineComponent({ |
2301 | 2307 | ) |
2302 | 2308 | }, |
2303 | 2309 | destroyInstance: function (id) { |
2304 | | - if (this.data.find(i => i.id === id)?.enabled) { |
| 2310 | + const instance = this.data.find(i => i.id === id) |
| 2311 | +
|
| 2312 | + if (instance?.enabled) { |
2305 | 2313 | return this.q.notify({ |
2306 | 2314 | message: |
2307 | 2315 | 'You can only destroy a disabled instance. Please disable it first.', |
2308 | 2316 | color: 'warning' |
2309 | 2317 | }) |
2310 | 2318 | } |
| 2319 | + if (instance?.hasActiveFiatSubscription) { |
| 2320 | + return this.q.notify({ |
| 2321 | + message: |
| 2322 | + 'Please end the subscription from /subscriptions for this instance first', |
| 2323 | + color: 'warning' |
| 2324 | + }) |
| 2325 | + } |
2311 | 2326 | this.confirm( |
2312 | 2327 | `Destroy ${id}`, |
2313 | 2328 | 'Are you sure you want to destroy?' + |
@@ -2470,12 +2485,37 @@ export default defineComponent({ |
2470 | 2485 | return false |
2471 | 2486 | } |
2472 | 2487 | }, |
| 2488 | + getActiveFiatSubscriptionInstanceIds(subscriptions = []) { |
| 2489 | + return new Set( |
| 2490 | + subscriptions |
| 2491 | + .filter(subscription => { |
| 2492 | + if (!subscription) { |
| 2493 | + return false |
| 2494 | + } |
| 2495 | +
|
| 2496 | + if (+subscription.ended_at) { |
| 2497 | + return false |
| 2498 | + } |
| 2499 | +
|
| 2500 | + return true |
| 2501 | + }) |
| 2502 | + .map(subscription => `${subscription.instance_id}`) |
| 2503 | + ) |
| 2504 | + }, |
2473 | 2505 | refreshState: async function () { |
2474 | 2506 | try { |
2475 | | - const {data} = await saas.getInstances() |
| 2507 | + const [{data: instancesData}, {data: subscriptionsData}] = |
| 2508 | + await Promise.all([saas.getInstances(), saas.getUserSubscriptions()]) |
2476 | 2509 |
|
2477 | 2510 | await this.serverStatus() |
2478 | | - const tableData = (data || []).map(i => saas.mapInstance(i)) |
| 2511 | + const activeFiatSubscriptionInstanceIds = |
| 2512 | + this.getActiveFiatSubscriptionInstanceIds(subscriptionsData || []) |
| 2513 | + const tableData = (instancesData || []).map(i => ({ |
| 2514 | + ...saas.mapInstance(i), |
| 2515 | + hasActiveFiatSubscription: activeFiatSubscriptionInstanceIds.has( |
| 2516 | + `${i.id}` |
| 2517 | + ) |
| 2518 | + })) |
2479 | 2519 |
|
2480 | 2520 | this.activityStats[0].value = tableData.length |
2481 | 2521 | this.activityStats[1].value = tableData.filter( |
|
0 commit comments