Cleanup the pages

This commit is contained in:
Manav Rathi 2024-04-03 19:59:32 +05:30
parent aa5422db6c
commit 7a729183e2
No known key found for this signature in database
4 changed files with 23 additions and 31 deletions

View file

@ -1,9 +1,9 @@
import { Container } from "components/Container";
import { Spinner } from "components/Spinner";
import * as React from "react";
import React, { useEffect } from "react";
export default function DesktopRedirect() {
React.useEffect(() => {
const Page: React.FC = () => {
useEffect(() => {
const currentURL = new URL(window.location.href);
const desktopRedirectURL = new URL("ente://app/gallery");
desktopRedirectURL.search = currentURL.search;
@ -15,4 +15,6 @@ export default function DesktopRedirect() {
<Spinner />
</Container>
);
}
};
export default Page;

View file

@ -1,24 +1,19 @@
import { Container } from "components/Container";
import { Spinner } from "components/Spinner";
import * as React from "react";
import React, { useEffect } from "react";
import { parseAndHandleRequest } from "services/billing-service";
import S from "utils/strings";
export default function Home() {
const Page: React.FC = () => {
const [failed, setFailed] = React.useState(false);
React.useEffect(() => {
async function main() {
try {
await parseAndHandleRequest();
} catch {
setFailed(true);
}
}
// TODO: audit
// eslint-disable-next-line @typescript-eslint/no-floating-promises
main();
useEffect(() => {
parseAndHandleRequest().catch(() => {
setFailed(true);
});
}, []);
return <Container>{failed ? S.error_generic : <Spinner />}</Container>;
}
};
export default Page;

View file

@ -1,11 +1,4 @@
// TODO: Audit this and other eslints
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-confusing-void-expression */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import { loadStripe } from "@stripe/stripe-js";
/**
@ -180,11 +173,11 @@ const createCheckoutSession = async (
throw new Error(`Unexpected response for ${url}: ${JSON.stringify(json)}`);
};
export async function updateSubscription(
const updateSubscription = async (
productID: string,
paymentToken: string,
redirectURL: string,
) {
) => {
try {
const accountCountry = await getUserStripeAccountCountry(paymentToken);
const stripe = await getStripe(redirectURL, accountCountry);
@ -193,16 +186,18 @@ export async function updateSubscription(
productID,
);
switch (status) {
case "success":
case "success": {
// Subscription was updated successfully, nothing more required
return redirectToApp(redirectURL, "success");
}
case "requires_payment_method":
case "requires_payment_method": {
return redirectToApp(
redirectURL,
"fail",
"requires_payment_method",
);
}
case "requires_action": {
const { error } = await stripe.confirmCardPayment(clientSecret);
@ -236,7 +231,7 @@ export async function updateSubscription(
redirectToApp(redirectURL, "fail", "server_error");
throw e;
}
}
};
type PaymentStatus = "success" | "requires_action" | "requires_payment_method";

View file

@ -9,7 +9,7 @@ body {
flex-direction: column;
justify-content: center;
align-items: center;
min-width: 80svh;
min-height: 100svh;
}
.loading-spinner {