Skip to content

Commit

Permalink
fix: gitops catalog filter and handle subscription error (#512)
Browse files Browse the repository at this point in the history
* fix: workload creation

* fix: gitops catalog filter
  • Loading branch information
CristhianF7 authored Sep 3, 2024
1 parent 59365c2 commit f5e5b98
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
13 changes: 2 additions & 11 deletions app/settings/subscription/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import React from 'react';
import axios from 'axios';
import sortBy from 'lodash/sortBy';

import Subscription from '@/containers/Subscription/Subscription';
import { Plan } from '@/types/plan';

async function getProductPlans() {
const { SAAS_API_URL = '' } = process.env;

const { data } = await axios.get<Array<Plan>>(`${SAAS_API_URL}/api/v1/payment/plans`);
import { getProductPlans } from '../page';

return sortBy(data, (product) => product && product.metadata && product.metadata['order']);
}
import Subscription from '@/containers/Subscription/Subscription';

export default async function Page({ params }: { params: { slug: string } }) {
const plans = await getProductPlans();
Expand Down
12 changes: 9 additions & 3 deletions app/settings/subscription/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import sortBy from 'lodash/sortBy';
import Subscription from '@/containers/Subscription/Subscription';
import { Plan } from '@/types/plan';

async function getProductPlans() {
export async function getProductPlans() {
const { SAAS_API_URL = '' } = process.env;

const { data } = await axios.get<Array<Plan>>(`${SAAS_API_URL}/api/v1/payment/plans`);
try {
const { data } = await axios.get<Array<Plan>>(`${SAAS_API_URL}/api/v1/payment/plans`);

return sortBy(data, (product) => product && product.metadata && product.metadata['order']);
return sortBy(data, (product) => product && product.metadata && product.metadata['order']);
} catch (error) {
// eslint-disable-next-line no-console
console.log('error getting product plans', error);
return [];
}
}

export default async function Page() {
Expand Down
9 changes: 6 additions & 3 deletions hooks/usePaywall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAppSelector } from '@/redux/store';
import { SaasFeatures, SaasPlans } from '@/types/subscription';

export const CLUSTERS_LIMIT_FALLBACK: { [key: string]: number } = {
[SaasPlans.Community]: 3,
[SaasPlans.Community]: 4,
[SaasPlans.Pro]: 10,
[SaasPlans.Enterprise]: Infinity,
};
Expand All @@ -30,9 +30,12 @@ export default function usePaywall() {
}

if (!license?.licenseKey) {
// Gets and checks number of clusters to allow workload creation
return (
Object.keys(clusterMap).filter((clusterKey) => clusterKey != 'draft').length <
CLUSTERS_LIMIT_FALLBACK[SaasPlans.Community]
Object.keys(clusterMap).filter((clusterKey) => {
const { status } = clusterMap[clusterKey];
return clusterKey != 'draft' && status != 'deleted';
}).length < CLUSTERS_LIMIT_FALLBACK[SaasPlans.Community]
);
}

Expand Down
10 changes: 8 additions & 2 deletions redux/slices/applications.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ const applicationsSlice = createSlice({
state.installedClusterAppNames = [];
})
.addCase(getClusterApplications.fulfilled, (state, { payload }) => {
state.clusterApplications = payload;
state.installedClusterAppNames = payload.map((app) => app.name);
if (payload) {
state.clusterApplications = payload;

state.installedClusterAppNames = payload.map((app) => app.name);
} else {
state.installedClusterAppNames = [];
state.clusterApplications = [];
}
})
.addCase(getClusterApplications.rejected, (state) => {
state.clusterApplications = [];
Expand Down

0 comments on commit f5e5b98

Please sign in to comment.