Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE Hotfix Stripe #26

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frontend/src/components/WorkspaceSettings/Billing/Billing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getSubscriptionsApiV1BillingSubscriptionGet } from 'api/generated';
import BillingPaidSkeleton from './BillingPaidView/BillingPaidSkeleton';
import BillingPaidView from './BillingPaidView/BillingPaidView';
import FirstBilling from './FirstBilling/FirstBilling';

import { Subscriptions } from './billing.types';

const Billing = () => {
Expand All @@ -13,15 +14,15 @@ const Billing = () => {

const getSubscription = async () => {
const response = (await getSubscriptionsApiV1BillingSubscriptionGet()) as Subscriptions[];
setSubscriptions([...response]);
response && setSubscriptions([...response]);
setIsLoading(false);
};

useEffect(() => {
getSubscription();
}, []);

const isPaid = subscriptions.length > 0;
const isPaid = subscriptions.length > 0 && subscriptions[0]?.status === 'active';

if (isLoading) {
return <BillingPaidSkeleton />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const BillingHistory = () => {
try {
const response = await listAllChargesApiV1BillingChargesGet();

setTransactions([...response]);
response && setTransactions([...response]);
setLoading(false);
} catch (err) {
logger.error(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useStripe, useElements, CardElement } from '@stripe/react-stripe-js';
import { StripeCardElement } from '@stripe/stripe-js';

import { updatePaymentMethodApiV1BillingPaymentMethodPost } from 'api/generated';

import logger from 'helpers/services/logger';

import ActionDialog from 'components/base/Dialog/ActionDialog/ActionDialog';
Expand Down Expand Up @@ -41,10 +42,12 @@ const BillingMethodDialog = ({ isDialogOpen, handleCloseDialog }: BillingMethodD

if (paymentMethod.error) {
setErrorMessage(paymentMethod.error.message as string);

logger.error(paymentMethod.error);
} else {
updatePaymentMethodApiV1BillingPaymentMethodPost({ payment_method_id: paymentMethod.paymentMethod.id });
handleCloseDialog();

window.location.reload();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const BillingMethods = ({ clientSecret }: { clientSecret: string }) => {
const getPaymentMethods = async () => {
try {
const response = await getPaymentMethodApiV1BillingPaymentMethodGet();
setPaymentMethods(response as any[]);
response && setPaymentMethods(response as any[]);
} catch (err) {
logger.error(err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import ActionDialog from 'components/base/Dialog/ActionDialog/ActionDialog';

import { updateSubscriptionApiV1BillingSubscriptionSubscriptionIdPut } from 'api/generated';

import logger from 'helpers/services/logger';

import { BillingText } from '../Billing.styles';
import { FlexContainer } from 'components/base/Container/Container.styles';

import { Loader } from 'components/Loader';

import { constants } from '../billing.constants';

import { resError } from 'helpers/types/resError';

interface BillingPlanCardDialogProps {
isDialogOpen: boolean;
handleCloseDialog: () => void;
Expand All @@ -37,18 +37,18 @@ const BillingPlanCardDialog = (props: BillingPlanCardDialogProps) => {
const handleSubmit = async () => {
setLoading(true);

try {
await updateSubscriptionApiV1BillingSubscriptionSubscriptionIdPut(subscriptionId, {
price_id: priceId,
quantity: quantity
});

window.location.reload();
} catch (err) {
setErrorMsg(constants.firstBilling.errorMassageContent);
setLoading(false);

logger.error(err);
const response = await updateSubscriptionApiV1BillingSubscriptionSubscriptionIdPut(subscriptionId, {
price_id: priceId,
quantity: quantity
});

if (response) {
if ((response as unknown as resError).error_message) {
setErrorMsg(constants.firstBilling.errorMassageContent);
setLoading(false);
} else {
response && response.client_secret && window.location.reload();
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
listAllProductsApiV1BillingAvailableProductsGet
} from 'api/generated';

import logger from 'helpers/services/logger';

import BillingPlanCard from '../BillingPlanCard/BillingPlanCard';
import BillingPaymentWrapper from '../BillingPaymentWrapper';
import FirstBillingPayment from './FirstBillingPayment';
Expand All @@ -15,6 +13,8 @@ import { BillingText, FirstBillingContainer } from '../Billing.styles';

import { constants } from '../billing.constants';

import { resError } from 'helpers/types/resError';

interface ProductsResponseType {
default_price: string;
id: string;
Expand All @@ -34,21 +34,22 @@ const FirstBilling = () => {
};

const handleUpgradeClick = async (quantity: number) => {
try {
const payload = { price_id: product.default_price, quantity: quantity as number };
const response = (await createSubscriptionApiV1BillingSubscriptionPost(payload)) as { client_secret: string };
const payload = { price_id: product.default_price, quantity: quantity as number };
const response = (await createSubscriptionApiV1BillingSubscriptionPost(payload)) as { client_secret: string };

setClientSecret(response.client_secret);
} catch (err) {
logger.error(err);
setErrorMassage(constants.firstBilling.errorMassageContent);
}
response && setClientSecret(response.client_secret);
};

useEffect(() => {
getProductDetails();
}, []);

useEffect(() => {
if (clientSecret && (clientSecret as unknown as resError).error_message) {
setErrorMassage(constants.firstBilling.errorMassageContent);
}
}, [clientSecret]);

return (
<FirstBillingContainer>
<BillingPlanCard handleUpgradeClick={handleUpgradeClick} productQuantity={1} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ const WorkspaceSettings = () => {
const [memberSettings, setMemberSettings] = useState<MemberSchema[]>();
const [isLoading, setIsLoading] = useState(true);

const isAdmin = memberSettings && memberSettings[0].is_admin;
const isAdmin = memberSettings && memberSettings[0]?.is_admin;

const getMemberSettings = async () => {
const response = await retrieveOrganizationMembersApiV1OrganizationMembersGet();
setMemberSettings(response);

response && setMemberSettings(response);

setIsLoading(false);
};

Expand Down