Merge branch 'preview/advisor-short-path' into 'develop'

Preview/advisor short path

See merge request witapp/aura-webapp!78
This commit is contained in:
Daniil Chemerkin 2024-04-09 19:19:05 +00:00
commit d40cc37f76
4 changed files with 82 additions and 40 deletions

View File

@ -285,30 +285,39 @@ function App(): JSX.Element {
}
>
<Route
path={routes.client.advisorChatGender()}
element={<GenderPage />}
/>
<Route
path={routes.client.advisorChatBirthdate()}
element={<BirthdayPage />}
/>
<Route
path={routes.client.advisorChatBirthtime()}
element={<BirthtimePage />}
/>
<Route
path={routes.client.advisorChatBirthPlace()}
element={<BirthPlacePage />}
/>
<Route
path={routes.client.advisorChatSuccessPayment()}
element={<SuccessPaymentPage />}
/>
<Route
path={routes.client.advisorChatFailPayment()}
element={<FailPaymentPage />}
/>
element={
<CheckIsAuthOutlet
redirectUrl={routes.client.singlePaymentShortPath("chat.aura")}
pageType={EIsAuthPageType.private}
/>
}
>
<Route
path={routes.client.advisorChatGender()}
element={<GenderPage />}
/>
<Route
path={routes.client.advisorChatBirthdate()}
element={<BirthdayPage />}
/>
<Route
path={routes.client.advisorChatBirthtime()}
element={<BirthtimePage />}
/>
<Route
path={routes.client.advisorChatBirthPlace()}
element={<BirthPlacePage />}
/>
</Route>
</Route>
<Route
path={routes.client.advisorChatSuccessPayment()}
element={<SuccessPaymentPage />}
/>
<Route
path={routes.client.advisorChatFailPayment()}
element={<FailPaymentPage />}
/>
<Route
element={
@ -757,6 +766,30 @@ function Layout({ setIsSpecialOfferOpen }: LayoutProps): JSX.Element {
);
}
enum EIsAuthPageType {
private,
public,
}
interface ICheckIsAuthOutletProps {
redirectUrl: string;
pageType: EIsAuthPageType;
}
function CheckIsAuthOutlet({
redirectUrl,
pageType,
}: ICheckIsAuthOutletProps): JSX.Element {
const { user } = useAuth();
if (user && pageType === EIsAuthPageType.public) {
return <Navigate to={redirectUrl} replace={true} />;
}
if (!user && pageType === EIsAuthPageType.private) {
return <Navigate to={redirectUrl} replace={true} />;
}
return <Outlet />;
}
interface ICheckPurchasedSingleProductOutletProps {
productKey: string;
isProductPage: boolean;

View File

@ -14,6 +14,7 @@ import Message from "./components/Message";
import LoaderDots from "./components/LoaderDots";
import useDetectScroll from "@smakss/react-scroll-direction";
import { getZodiacSignByDate } from "@/services/zodiac-sign";
import { useAuth } from "@/auth";
function AdvisorChatPage() {
const isPrivateChat = window.location.href.includes("/advisor-chat-private/");
@ -29,6 +30,7 @@ function AdvisorChatPage() {
const { gender, birthtime, birthPlace } = useSelector(
selectors.selectQuestionnaire
);
const { user } = useAuth();
const [assistant, setAssistant] = useState<IAssistant>();
const [messageText, setMessageText] = useState("");
const [textareaRows, setTextareaRows] = useState(1);
@ -200,11 +202,13 @@ function AdvisorChatPage() {
};
const getContentMessage = (messageText: string) => {
const content = `#USER INFO: zodiac sign - ${zodiacSign}; gender - ${gender}; birthdate - ${birthdate}; name - ${
username || "unknown"
}; birthtime - ${birthtime || "unknown"}; birthPlace - ${
birthPlace || "unknown"
}# ${messageText}`;
const sign = zodiacSign || user?.profile?.sign || "unknown";
const _gender = gender || user?.profile?.gender || "unknown";
const _birthDate = birthdate || user?.profile?.birthday || "unknown";
const _birthtime = birthtime || "unknown";
const _birthPlace = birthPlace || user?.profile?.birthplace || "unknown";
const name = username || user?.profile?.full_name || "unknown";
const content = `#USER INFO: zodiac sign - ${sign}; gender - ${_gender}; birthdate - ${_birthDate}; name - ${name}; birthtime - ${_birthtime}; birthPlace - ${_birthPlace}# ${messageText}`;
return content;
};

View File

@ -21,8 +21,8 @@ import { useSinglePayment } from "@/hooks/payment/useSinglePayment";
function PaymentWithEmailPage() {
const { productId } = useParams();
const { t, i18n } = useTranslation();
const tokenFromStore = useSelector(selectors.selectToken);
const { signUp, user: userFromStore } = useAuth();
// const tokenFromStore = useSelector(selectors.selectToken);
const { signUp, user: userFromStore, token: tokenFromStore } = useAuth();
const api = useApi();
const timezone = getClientTimezone();
const dispatch = useDispatch();
@ -164,8 +164,7 @@ function PaymentWithEmailPage() {
useEffect(() => {
handleAuthUser();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [handleAuthUser]);
return (
<div className={`${styles.page} page`}>

View File

@ -69,18 +69,16 @@ export const useSinglePayment = () => {
token,
});
if (
"active" in purchased &&
purchased.active &&
productUrls[productKey].length
) {
return navigate(productUrls[productKey]);
if ("active" in purchased && purchased.active) {
return true;
}
return false;
} catch (error) {
return false;
console.error(error);
}
},
[api, navigate]
[api]
);
const createSinglePayment = useCallback(
@ -98,7 +96,14 @@ export const useSinglePayment = () => {
return;
}
setProduct(product);
await checkProductPurchased(user?.email || "", targetProductKey, token);
const isPurchased = await checkProductPurchased(
user?.email || "",
targetProductKey,
token
);
if (isPurchased && productUrls[targetProductKey].length) {
return navigate(productUrls[targetProductKey]);
}
const paymentIntent = await api.createSinglePayment({
token,
data: {
@ -140,6 +145,7 @@ export const useSinglePayment = () => {
gender,
getCurrentProduct,
handlerPaymentIntentResult,
navigate,
]
);