Billing / plus frontend (#2130)

* [wip] initial

* [wip] subscriptions/plus frontend

* [wip] finish payment flow

* Charges page

* finish most subscriptions work

* Finish

* update eslint

* Fix issues

* fix intl extract

* fix omorphia locale extract

* fix responsiveness

* fix lint
This commit is contained in:
Geometrically
2024-08-15 23:21:30 -07:00
committed by GitHub
parent 1b3744baa2
commit 3a4843fb46
44 changed files with 2353 additions and 201 deletions

View File

@@ -39,6 +39,16 @@ export const initAuth = async (oldToken = null) => {
authCookie.value = route.query.code;
}
if (route.fullPath.includes("new_account=true") && route.path !== "/auth/welcome") {
const redirect = route.path.startsWith("/auth/") ? null : route.fullPath;
await navigateTo(
`/auth/welcome?authToken=${route.query.code}${
redirect ? `&redirect=${encodeURIComponent(redirect)}` : ""
}`,
);
}
if (authCookie.value) {
auth.token = authCookie.value;

View File

@@ -0,0 +1,6 @@
export const useUserCountry = () =>
useState("userCountry", () => {
const headers = useRequestHeaders(["cf-ipcountry"]);
return headers["cf-ipcountry"] ?? "US";
});

View File

@@ -12,20 +12,27 @@ export const initUser = async () => {
const auth = (await useAuth()).value;
const user = {
notifications: [],
collections: [],
follows: [],
subscriptions: [],
lastUpdated: 0,
};
if (auth.user && auth.user.id) {
try {
const [follows, collections] = await Promise.all([
useBaseFetch(`user/${auth.user.id}/follows`),
useBaseFetch(`user/${auth.user.id}/collections`, { apiVersion: 3 }),
const headers = {
Authorization: auth.token,
};
const [follows, collections, subscriptions] = await Promise.all([
useBaseFetch(`user/${auth.user.id}/follows`, { headers }, true),
useBaseFetch(`user/${auth.user.id}/collections`, { apiVersion: 3, headers }, true),
useBaseFetch(`billing/subscriptions`, { internal: true, headers }, true),
]);
user.collections = collections;
user.follows = follows;
user.subscriptions = subscriptions;
user.lastUpdated = Date.now();
} catch (err) {
console.error(err);
@@ -170,6 +177,5 @@ export const logout = async () => {
await useAuth("none");
useCookie("auth-token").value = null;
await navigateTo("/");
stopLoading();
};