mirror of
https://github.com/fergalmoran/supanextail.git
synced 2025-12-22 09:17:54 +00:00
Fix every issues with eslint (unicorn + sonar)
This commit is contained in:
@@ -38,7 +38,9 @@ const MailingList = (): JSX.Element => {
|
||||
})
|
||||
.then((result) => {
|
||||
if (result.status === 200) {
|
||||
toast.success(result.data.message);
|
||||
toast.success(
|
||||
'Your email has been succesfully added to the mailing list. Welcome 👋'
|
||||
);
|
||||
setLoading(false);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@ const PaymentModal = ({
|
||||
open,
|
||||
setPayment,
|
||||
}: PaymentModalProperties): JSX.Element => {
|
||||
function closeModal() {
|
||||
function closeModal(): void {
|
||||
setPayment(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,19 +10,20 @@ import { getSub, supabase } from 'utils/supabaseClient';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import axios from 'axios';
|
||||
import { definitions } from 'types/database/index';
|
||||
import router from 'next/router';
|
||||
import { useAuth } from 'utils/AuthContext';
|
||||
|
||||
const Pricing = (): JSX.Element => {
|
||||
const { user, session } = useAuth();
|
||||
const [customerId, setCustomerId] = useState<null | string>(null);
|
||||
const [sub, setSub] = useState(false);
|
||||
const [customerId, setCustomerId] = useState<undefined | string>();
|
||||
const [sub, setSub] = useState<definitions['subscriptions'] | undefined>();
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
getSub().then((result) => setSub(result));
|
||||
supabase
|
||||
.from('subscriptions')
|
||||
void getSub().then((result) => setSub(result));
|
||||
void supabase
|
||||
.from<definitions['subscriptions']>('subscriptions')
|
||||
.select(`customer_id`)
|
||||
.eq('id', user.id)
|
||||
.single()
|
||||
@@ -32,31 +33,37 @@ const Pricing = (): JSX.Element => {
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
interface Test {
|
||||
url: string;
|
||||
}
|
||||
|
||||
const handleSubmit = async (
|
||||
e: React.SyntheticEvent<HTMLButtonElement>,
|
||||
event: React.SyntheticEvent<HTMLButtonElement>,
|
||||
priceId: string
|
||||
) => {
|
||||
e.preventDefault();
|
||||
): Promise<void> => {
|
||||
event.preventDefault();
|
||||
// Create a Checkout Session. This will redirect the user to the Stripe website for the payment.
|
||||
if (sub) {
|
||||
axios
|
||||
.post('/api/stripe/customer-portal', {
|
||||
customerId,
|
||||
})
|
||||
.then((result) => {
|
||||
router.push(result.data.url);
|
||||
});
|
||||
} else
|
||||
axios
|
||||
.post('/api/stripe/create-checkout-session', {
|
||||
if (user && session) {
|
||||
if (sub) {
|
||||
const stripeInfo = await axios.post<Test>(
|
||||
'/api/stripe/customerPortal',
|
||||
{
|
||||
customerId,
|
||||
}
|
||||
);
|
||||
void router.push(stripeInfo.data.url);
|
||||
} else {
|
||||
const stripeInfo = await axios.post<Test>('/api/stripe/checkout', {
|
||||
priceId,
|
||||
email: user.email,
|
||||
customerId,
|
||||
userId: user.id,
|
||||
tokenId: session.access_token,
|
||||
pay_mode: 'subscription',
|
||||
})
|
||||
.then((result) => router.push(result.data.url));
|
||||
});
|
||||
void router.push(stripeInfo.data.url);
|
||||
}
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div>
|
||||
@@ -102,8 +109,8 @@ const Pricing = (): JSX.Element => {
|
||||
{user ? (
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={(e) => {
|
||||
handleSubmit(e, 'price_1JtHhaDMjD0UnVmM5uCyyrWn');
|
||||
onClick={(event) => {
|
||||
void handleSubmit(event, 'price_1JtHhaDMjD0UnVmM5uCyyrWn');
|
||||
}}>
|
||||
{sub ? 'Handle subscription' : 'Subscribe'}
|
||||
</button>
|
||||
@@ -136,8 +143,8 @@ const Pricing = (): JSX.Element => {
|
||||
{user ? (
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={(e) => {
|
||||
handleSubmit(e, 'price_1JtHhaDMjD0UnVmM5uCyyrWn');
|
||||
onClick={(event) => {
|
||||
void handleSubmit(event, 'price_1JtHhaDMjD0UnVmM5uCyyrWn');
|
||||
}}>
|
||||
{sub ? 'Handle subscription' : 'Subscribe'}
|
||||
</button>
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
import { ApiError, Session, UserCredentials } from '@supabase/gotrue-js';
|
||||
|
||||
import { IoLogoGoogle } from 'react-icons/io';
|
||||
import router from 'next/router';
|
||||
import { toast } from 'react-toastify';
|
||||
import { useState } from 'react';
|
||||
|
||||
type LoginProperties = {
|
||||
resetPassword: (email: string) => Promise<{ error: { message: string } }>;
|
||||
signIn: ({}) => Promise<{
|
||||
data: Record<string, unknown>;
|
||||
error: { message: string };
|
||||
resetPassword: (data: string) => Promise<{
|
||||
data: {} | null;
|
||||
error: ApiError | null;
|
||||
}>;
|
||||
|
||||
signIn: (data: UserCredentials) => Promise<{
|
||||
user: Session['user'] | null;
|
||||
session: Session | null;
|
||||
error: ApiError | null;
|
||||
}>;
|
||||
};
|
||||
|
||||
@@ -17,13 +24,11 @@ const Login = ({ resetPassword, signIn }: LoginProperties): JSX.Element => {
|
||||
const [forgot, setForgot] = useState(false);
|
||||
|
||||
const resetPasswordLogin = async (): Promise<void> => {
|
||||
await resetPassword(email).then(
|
||||
(result: { error: { message: string } }) => {
|
||||
if (result.error) {
|
||||
toast.error(result.error.message);
|
||||
} else toast.success('Check your email to reset your password!');
|
||||
}
|
||||
);
|
||||
await resetPassword(email).then((result: { error: ApiError | null }) => {
|
||||
if (result.error) {
|
||||
toast.error(result.error.message);
|
||||
} else toast.success('Check your email to reset your password!');
|
||||
});
|
||||
};
|
||||
|
||||
const login = async (
|
||||
@@ -35,19 +40,14 @@ const Login = ({ resetPassword, signIn }: LoginProperties): JSX.Element => {
|
||||
await signIn({
|
||||
email,
|
||||
password,
|
||||
}).then(
|
||||
(result: {
|
||||
data: Record<string, unknown>;
|
||||
error: { message: string };
|
||||
}) => {
|
||||
if (result.data) {
|
||||
void router.push('/');
|
||||
}
|
||||
if (result.error) {
|
||||
toast.error(result.error.message);
|
||||
}
|
||||
}).then((result) => {
|
||||
if (result) {
|
||||
void router.push('/');
|
||||
}
|
||||
);
|
||||
if (result.error) {
|
||||
toast.error(result.error.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user