Merge branch 'hotfix/oldServerRemove' into 'main'
remove legacy server from compatibility v2 See merge request witapp/aura-webapp!819
This commit is contained in:
commit
057a7fbfec
@ -41,9 +41,7 @@ const api = {
|
||||
getAppConfig: createMethod<Apps.Payload, Apps.Response>(Apps.createRequest),
|
||||
// getElement: createMethod<Element.Payload, Element.Response>(Element.createRequest),
|
||||
getElements: createMethod<Elements.Payload, Elements.Response>(Elements.createRequest),
|
||||
getUser: createMethod<User.GetPayload, User.Response>(User.createGetRequest),
|
||||
getMe: createMethod<User.GetPayload, User.IMeResponse>(User.createMeRequest),
|
||||
updateUser: createMethod<User.PatchPayload, User.Response>(User.createPatchRequest),
|
||||
getAssets: createMethod<Assets.Payload, Assets.Response>(Assets.createRequest),
|
||||
getAssetCategories: createMethod<AssetCategories.Payload, AssetCategories.Response>(AssetCategories.createRequest),
|
||||
getDailyForecasts: createMethod<DailyForecasts.Payload, DailyForecasts.Response>(DailyForecasts.createRequest),
|
||||
@ -102,7 +100,6 @@ const api = {
|
||||
// Subscriptions
|
||||
// getSubscriptionPlans: createMethod<SubscriptionPlans.Payload, SubscriptionPlans.Response>(SubscriptionPlans.createRequest),
|
||||
// getSubscriptionCheckout: createMethod<SubscriptionCheckout.Payload, SubscriptionCheckout.Response>(SubscriptionCheckout.createRequest),
|
||||
getSubscriptionStatus: createMethod<SubscriptionStatus.Payload, SubscriptionStatus.Response>(SubscriptionStatus.createRequest),
|
||||
// new get subscription status
|
||||
getSubscriptionStatusNew: createMethod<SubscriptionStatus.Payload, SubscriptionStatus.ResponseNew>(SubscriptionStatus.createRequestNew),
|
||||
getUserSubscriptions: createMethod<UserSubscriptions.Payload, UserSubscriptions.ResponseGet>(UserSubscriptions.createRequestGet),
|
||||
|
||||
@ -116,21 +116,6 @@ export interface Subscription {
|
||||
last_sent_at: string | null;
|
||||
}
|
||||
|
||||
export const createGetRequest = ({ token }: GetPayload): Request => {
|
||||
const url = new URL(routes.server.user());
|
||||
return new Request(url, { method: "GET", headers: getAuthHeaders(token) });
|
||||
};
|
||||
|
||||
export const createPatchRequest = ({ token, user }: PatchPayload): Request => {
|
||||
const url = new URL(routes.server.user());
|
||||
const body = JSON.stringify({ user });
|
||||
return new Request(url, {
|
||||
method: "PATCH",
|
||||
headers: getAuthHeaders(token),
|
||||
body,
|
||||
});
|
||||
};
|
||||
|
||||
export enum ESourceAuthorization {
|
||||
"aura.main" = "aura.main",
|
||||
"aura.palmistry" = "aura.palmistry",
|
||||
@ -249,9 +234,8 @@ export interface IUser {
|
||||
sign: boolean;
|
||||
signDate: string;
|
||||
password: string;
|
||||
externalId: string;
|
||||
klaviyoId: string;
|
||||
// stripeId: string | null;
|
||||
externalId?: string;
|
||||
klaviyoId?: string;
|
||||
assistants: string[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
|
||||
@ -4,17 +4,6 @@ import { getAuthHeaders } from "../utils"
|
||||
|
||||
export type Payload = AuthPayload
|
||||
|
||||
export interface Response {
|
||||
user: {
|
||||
has_subscription: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export const createRequest = ({ token }: Payload): Request => {
|
||||
const url = new URL(routes.server.subscriptionStatus())
|
||||
return new Request(url, { method: 'GET', headers: getAuthHeaders(token) })
|
||||
}
|
||||
|
||||
export interface ResponseNew {
|
||||
subscription: boolean;
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ export interface AuthContextValue {
|
||||
user: User.User | null
|
||||
token: AuthToken
|
||||
logout: () => void
|
||||
signUp: (token: AuthToken, user: User.User, newUser?: IUser, isAnonymous?: boolean) => AuthToken
|
||||
signUp: (token: AuthToken, newUser?: IUser, isAnonymous?: boolean) => AuthToken
|
||||
}
|
||||
|
||||
export const AuthContext = createContext<AuthContextValue>({} as AuthContextValue)
|
||||
|
||||
@ -4,6 +4,7 @@ import { actions, selectors } from "../store";
|
||||
import { AuthToken, User } from "../api";
|
||||
import { AuthContext } from "./AuthContext";
|
||||
import { IUser } from "@/api/resources/User";
|
||||
import { mapIUserToLegacy } from "@/services/user-adapter";
|
||||
|
||||
export function AuthProvider({
|
||||
children,
|
||||
@ -14,15 +15,16 @@ export function AuthProvider({
|
||||
const { gender, partnerGender, birthdate, partnerBirthdate, birthPlace, partnerBirthPlace } = useSelector(selectors.selectQuestionnaire);
|
||||
|
||||
const signUp = useCallback(
|
||||
(token: AuthToken, user: User.User, newUser?: IUser, isAnonymous?: boolean): AuthToken => {
|
||||
(token: AuthToken, newUser?: IUser, isAnonymous?: boolean): AuthToken => {
|
||||
dispatch(actions.token.update(token));
|
||||
dispatch(actions.user.update(user));
|
||||
dispatch(actions.form.addEmail(user.email));
|
||||
if (user.profile.birthday?.length) {
|
||||
dispatch(actions.form.addDate(user.profile.birthday.split(" ")[0]));
|
||||
const legacyUser: User.User = newUser ? mapIUserToLegacy(newUser) : user;
|
||||
dispatch(actions.user.update(legacyUser));
|
||||
dispatch(actions.form.addEmail(legacyUser.email));
|
||||
if (legacyUser.profile.birthday?.length) {
|
||||
dispatch(actions.form.addDate(legacyUser.profile.birthday.split(" ")[0]));
|
||||
dispatch(
|
||||
actions.form.addTime(
|
||||
new Date(user.profile.birthday).toLocaleTimeString()
|
||||
new Date(legacyUser.profile.birthday).toLocaleTimeString()
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -35,14 +37,10 @@ export function AuthProvider({
|
||||
partnerBirthdate: newUser.partner?.birthdate || partnerBirthdate || undefined,
|
||||
partnerGender: newUser.partner?.gender || partnerGender || undefined,
|
||||
}))
|
||||
|
||||
dispatch(actions.user.update({
|
||||
username: newUser.profile?.name ?? undefined,
|
||||
}));
|
||||
}
|
||||
return token;
|
||||
},
|
||||
[dispatch, gender, partnerGender, birthdate, partnerBirthdate, birthPlace, partnerBirthPlace]
|
||||
[dispatch, gender, partnerGender, birthdate, partnerBirthdate, birthPlace, partnerBirthPlace, user]
|
||||
);
|
||||
const logout = useCallback(() => dispatch(actions.reset()), [dispatch]);
|
||||
const auth = useMemo(
|
||||
|
||||
@ -2,7 +2,6 @@ import {
|
||||
useState,
|
||||
useEffect,
|
||||
useRef,
|
||||
useCallback,
|
||||
useMemo,
|
||||
useLayoutEffect
|
||||
} from "react";
|
||||
@ -56,16 +55,12 @@ import DidYouKnowPage from "../DidYouKnowPage";
|
||||
import FreePeriodInfoPage from "../FreePeriodInfoPage";
|
||||
import FeedbackPage from "../FeedbackPage";
|
||||
import CompatibilityPage from "../Compatibility";
|
||||
import BreathPage from "../BreathPage";
|
||||
import PriceListPage from "../PriceListPage";
|
||||
import CompatResultPage from "../CompatResultPage";
|
||||
import HomePage from "../HomePage";
|
||||
import UserCallbacksPage from "../UserCallbacksPage";
|
||||
import NavbarFooter, { INavbarHomeItems } from "../NavbarFooter";
|
||||
import { EPathsFromHome } from "@/store/siteConfig";
|
||||
import parseAPNG, { APNG } from "apng-js";
|
||||
import { useApi, useApiCall } from "@/api";
|
||||
import { Asset } from "@/api/resources/Assets";
|
||||
import PaymentResultPage from "../PaymentPage/results";
|
||||
import PaymentSuccessPage from "../PaymentPage/results/SuccessPage";
|
||||
import PaymentFailPage from "../PaymentPage/results/ErrorPage";
|
||||
@ -171,13 +166,7 @@ ReactGA.initialize(gaMeasurementId);
|
||||
|
||||
function App(): JSX.Element {
|
||||
const location = useLocation();
|
||||
const [leoApng, setLeoApng] = useState<Error | APNG>(Error);
|
||||
useScrollToTop({ scrollBehavior: "auto" });
|
||||
// const [
|
||||
// padLockApng,
|
||||
// setPadLockApng,
|
||||
// ] = useState<Error | APNG>(Error);
|
||||
const api = useApi();
|
||||
const dispatch = useDispatch();
|
||||
const { user } = useAuth();
|
||||
const { session } = useSession();
|
||||
@ -282,36 +271,6 @@ function App(): JSX.Element {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const assetsData = useCallback(async () => {
|
||||
const { assets } = await api.getAssets({
|
||||
category: String("au"),
|
||||
});
|
||||
return assets;
|
||||
}, [api]);
|
||||
|
||||
const { data } = useApiCall<Asset[]>(assetsData);
|
||||
// data
|
||||
|
||||
useEffect(() => {
|
||||
async function getApng() {
|
||||
if (!data) return;
|
||||
const response = await fetch(
|
||||
data.find((item) => item.key === "au.apng.leo")?.url || ""
|
||||
);
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
setLeoApng(parseAPNG(arrayBuffer));
|
||||
}
|
||||
getApng();
|
||||
}, [data]);
|
||||
|
||||
// useEffect(() => {
|
||||
// (async () => {
|
||||
// const response = await fetch("/padlock_icon_animation_closing.png");
|
||||
// const arrayBuffer = await response.arrayBuffer();
|
||||
// setPadLockApng(parseAPNG(arrayBuffer));
|
||||
// })();
|
||||
// }, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
dispatch(actions.form.addEmail(user.email));
|
||||
@ -472,10 +431,6 @@ function App(): JSX.Element {
|
||||
path={routes.client.compatibilityResult()}
|
||||
element={<CompatResultPage />}
|
||||
/>
|
||||
<Route
|
||||
path={routes.client.breath()}
|
||||
element={<BreathPage leoApng={leoApng} />}
|
||||
/>
|
||||
<Route
|
||||
path={routes.client.breathResult()}
|
||||
element={<UserCallbacksPage />}
|
||||
|
||||
@ -28,18 +28,8 @@ function AuthResultPage(): JSX.Element {
|
||||
(async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const apiUser = await api.getUser({ token: access_token });
|
||||
const apiUser = await api.getMe({ token: access_token });
|
||||
signUp(access_token, apiUser.user);
|
||||
const payload = {
|
||||
user: { profile_attributes: { birthday } },
|
||||
token: access_token,
|
||||
};
|
||||
const updatedUser = await api.updateUser(payload).catch((error) => {
|
||||
console.log("Error: ", error);
|
||||
});
|
||||
if (updatedUser?.user) {
|
||||
dispatch(actions.user.update(updatedUser.user));
|
||||
}
|
||||
dispatch(actions.status.update("registred"));
|
||||
setIsLoading(false);
|
||||
setTimeout(() => {
|
||||
|
||||
@ -4,50 +4,29 @@ import routes from "@/routes";
|
||||
import styles from "./styles.module.css";
|
||||
import MainButton from "../MainButton";
|
||||
import Title from "../Title";
|
||||
import { useApi, useApiCall } from "@/api";
|
||||
import { useCallback } from "react";
|
||||
import { Asset } from "@/api/resources/Assets";
|
||||
|
||||
function FeedbackPage(): JSX.Element {
|
||||
const { translate } = useTranslations();
|
||||
const navigate = useNavigate();
|
||||
const api = useApi();
|
||||
const handleNext = () => navigate(routes.client.freePeriodInfo());
|
||||
|
||||
const assetsData = useCallback(async () => {
|
||||
const { assets } = await api.getAssets({ category: String("au") });
|
||||
return assets;
|
||||
}, [api]);
|
||||
|
||||
const {
|
||||
data: assets,
|
||||
// isPending
|
||||
} = useApiCall<Asset[]>(assetsData);
|
||||
|
||||
const reviews = [
|
||||
{
|
||||
title: translate("aura.name_1.review"),
|
||||
text: translate("aura.review_1.content"),
|
||||
imageKey: "au.1.avatar",
|
||||
},
|
||||
{
|
||||
title: translate("aura.name_2.review"),
|
||||
text: translate("aura.review_2.content"),
|
||||
imageKey: "au.2.avatar",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<section className={`${styles.page} page`}>
|
||||
<div className={styles.reviews}>
|
||||
{reviews.map(({ title, text, imageKey }, index) => (
|
||||
{reviews.map(({ title, text }, index) => (
|
||||
<div className={styles.review} key={index}>
|
||||
<div className={styles.images}>
|
||||
<img
|
||||
className={styles["profile-picture"]}
|
||||
src={assets?.find((asset) => asset.key === imageKey)?.url}
|
||||
alt="profile picture"
|
||||
/>
|
||||
<div className={styles["header-container"]}>
|
||||
<Title variant="h3">{title}</Title>
|
||||
<img className={styles.stars} src="/5-stars.webp" alt="stop" />
|
||||
|
||||
@ -155,7 +155,6 @@ export const useAuthentication = () => {
|
||||
}
|
||||
metricService.reachGoal(EGoals.ENTERED_EMAIL, [EMetrics.YANDEX, EMetrics.KLAVIYO]);
|
||||
metricService.reachGoal(EGoals.LEAD, [EMetrics.FACEBOOK]);
|
||||
const { user } = await api.getUser({ token });
|
||||
const { user: userMe } = await api.getMe({ token });
|
||||
if (userId?.length) {
|
||||
metricService.userParams({
|
||||
@ -164,7 +163,7 @@ export const useAuthentication = () => {
|
||||
})
|
||||
metricService.setUserID(userId);
|
||||
}
|
||||
signUp(token, user, userMe);
|
||||
signUp(token, userMe);
|
||||
setToken(token);
|
||||
dispatch(actions.status.update("registred"));
|
||||
} catch (error: unknown) {
|
||||
@ -197,7 +196,6 @@ export const useAuthentication = () => {
|
||||
metricService.reachGoal(EGoals.ENTERED_EMAIL, [EMetrics.YANDEX, EMetrics.KLAVIYO]);
|
||||
metricService.reachGoal(EGoals.LEAD, [EMetrics.FACEBOOK]);
|
||||
}
|
||||
const { user } = await api.getUser({ token });
|
||||
const { user: userMe } = await api.getMe({ token });
|
||||
const userId = userIdFromApi || userMe?._id;
|
||||
if (userId?.length) {
|
||||
@ -209,7 +207,7 @@ export const useAuthentication = () => {
|
||||
})
|
||||
metricService.setUserID(userId);
|
||||
}
|
||||
signUp(token, user, userMe, isAnonymous);
|
||||
signUp(token, userMe, isAnonymous);
|
||||
setToken(token);
|
||||
dispatch(actions.userConfig.setAuthCode(authCode || ""));
|
||||
dispatch(actions.personalVideo.updateStatus({ generatingVideo: generatingVideo || false, videoId: videoId || "" }));
|
||||
@ -234,7 +232,6 @@ export const useAuthentication = () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
setError(null)
|
||||
const { user } = await api.getUser({ token });
|
||||
const { user: userMe } = await api.getMe({ token });
|
||||
const userId = userIdFromApi || userMe?._id;
|
||||
if (userId?.length) {
|
||||
@ -246,7 +243,7 @@ export const useAuthentication = () => {
|
||||
})
|
||||
metricService.setUserID(userId);
|
||||
}
|
||||
signUp(token, user, userMe, true);
|
||||
signUp(token, userMe, true);
|
||||
setToken(token);
|
||||
dispatch(actions.userConfig.setAuthCode(authCode || ""));
|
||||
dispatch(actions.personalVideo.updateStatus({ generatingVideo: generatingVideo || false, videoId: videoId || "" }));
|
||||
|
||||
@ -85,9 +85,8 @@ export function InitializationProvider({ children }: InitializationProviderProps
|
||||
try {
|
||||
logout();
|
||||
const { token } = await api.getRealToken({ token: jwtToken });
|
||||
const { user } = await api.getUser({ token });
|
||||
const { user: userMe } = await api.getMe({ token });
|
||||
signUp(token, user, userMe);
|
||||
signUp(token, userMe);
|
||||
} catch (error) {
|
||||
console.log("Error of get real token or get user: ");
|
||||
console.error(error);
|
||||
@ -102,19 +101,14 @@ export function InitializationProvider({ children }: InitializationProviderProps
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (!token.length || !user) return;
|
||||
const {
|
||||
user: { has_subscription },
|
||||
} = await api.getSubscriptionStatus({
|
||||
token,
|
||||
});
|
||||
|
||||
const { subscription: subscriptionStatusNew } =
|
||||
await api.getSubscriptionStatusNew({ token });
|
||||
|
||||
if ((has_subscription || subscriptionStatusNew) && user) {
|
||||
if (subscriptionStatusNew && user) {
|
||||
return dispatch(actions.status.update("subscribed"));
|
||||
}
|
||||
if (!has_subscription && !subscriptionStatusNew && user) {
|
||||
if (!subscriptionStatusNew && user) {
|
||||
return dispatch(actions.status.update("unsubscribed"));
|
||||
}
|
||||
if (!user) {
|
||||
|
||||
@ -508,15 +508,12 @@ const routes = {
|
||||
},
|
||||
server: {
|
||||
userLocale: () => ["https://ipapi.co", "json"].join("/"),
|
||||
user: () => [apiHost, prefix, "user.json"].join("/"),
|
||||
// new method for getting user data
|
||||
me: () => [dApiHost, "users", "me"].join("/"),
|
||||
// token: () => [apiHost, prefix, "auth", "token.json"].join("/"),
|
||||
elements: () => [oldBackendPrefix, "elements.json"].join("/"),
|
||||
zodiacs: (zodiac: string) =>
|
||||
[apiHost, prefix, "zodiacs", `${zodiac}.json`].join("/"),
|
||||
// element: (type: string) =>
|
||||
// [apiHost, prefix, "elements", `${type}.json`].join("/"),
|
||||
apps: (bundleId: string) =>
|
||||
[oldBackendPrefix, `${bundleId}.json`].join("/"),
|
||||
assets: (category: string) =>
|
||||
@ -618,10 +615,6 @@ const routes = {
|
||||
createChat: (assistantId: string) => [dApiHost, "chats", "create", assistantId].join("/"),
|
||||
|
||||
// Subscriptions
|
||||
subscriptionStatus: () =>
|
||||
[apiHost, prefix, "user", "subscription_receipts", "status.json"].join(
|
||||
"/"
|
||||
),
|
||||
subscriptionReceipts: () =>
|
||||
[apiHost, prefix, "user", "subscription_receipts.json"].join("/"),
|
||||
subscriptionStatusNew: () =>
|
||||
|
||||
55
src/services/user-adapter.ts
Normal file
55
src/services/user-adapter.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { User } from "@/api";
|
||||
import { IUser } from "@/api/resources/User";
|
||||
|
||||
export function mapIUserToLegacy(newUser: IUser): User.User {
|
||||
const legacyUser: User.User = {
|
||||
id: newUser._id || undefined,
|
||||
username: newUser.profile?.name ?? null,
|
||||
email: newUser.email || "",
|
||||
locale: newUser.locale || "",
|
||||
state: "",
|
||||
timezone: newUser.timezone || "",
|
||||
new_registration: false,
|
||||
stat: {
|
||||
last_online_at: null,
|
||||
prev_online_at: null,
|
||||
},
|
||||
profile: {
|
||||
full_name: newUser.profile?.name ?? null,
|
||||
gender: newUser.profile?.gender ?? null,
|
||||
birthday: newUser.profile?.birthdate ?? null,
|
||||
birthplace: newUser.profile?.birthplace?.address
|
||||
? {
|
||||
id: "",
|
||||
address: newUser.profile.birthplace.address,
|
||||
coords: "",
|
||||
}
|
||||
: null,
|
||||
age: typeof newUser.profile?.age === "number"
|
||||
? { years: newUser.profile.age, days: 0 }
|
||||
: null,
|
||||
sign: newUser.profile?.sign
|
||||
? {
|
||||
house: 0,
|
||||
ruler: "",
|
||||
dates: {
|
||||
start: { month: 0, day: 0 },
|
||||
end: { month: 0, day: 0 },
|
||||
},
|
||||
sign: newUser.profile.sign,
|
||||
char: "",
|
||||
polarity: "",
|
||||
modality: "",
|
||||
triplicity: "",
|
||||
}
|
||||
: null,
|
||||
userpic: null,
|
||||
userpic_mime_type: undefined,
|
||||
relationship_status: "",
|
||||
human_relationship_status: "",
|
||||
},
|
||||
daily_push_subs: [],
|
||||
};
|
||||
|
||||
return legacyUser;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user