Merged in fix/LOY-408-promo-client-side-dynamic-states (pull request #2956)
fix(LOY-408): Make auth parts of promohero client components * fix(LOY-408): Move auth parts of promohero client side * chore(LOY-408): remove unused code Approved-by: Linus Flood Approved-by: Matilda Landström
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { useRouter } from "next/navigation"
|
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { Button } from "@scandic-hotels/design-system/Button"
|
import { Button } from "@scandic-hotels/design-system/Button"
|
||||||
@@ -25,7 +25,6 @@ export default function ActivateOffer({
|
|||||||
}: ActivateOfferProps) {
|
}: ActivateOfferProps) {
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const lang = useLang()
|
const lang = useLang()
|
||||||
const router = useRouter()
|
|
||||||
const trpcUtils = trpc.useUtils()
|
const trpcUtils = trpc.useUtils()
|
||||||
|
|
||||||
async function handleActivateFlow() {
|
async function handleActivateFlow() {
|
||||||
@@ -41,8 +40,7 @@ export default function ActivateOffer({
|
|||||||
const activateCampaign = trpc.user.promoCampaign.add.useMutation({
|
const activateCampaign = trpc.user.promoCampaign.add.useMutation({
|
||||||
onSuccess: async (data) => {
|
onSuccess: async (data) => {
|
||||||
if (!data) return
|
if (!data) return
|
||||||
trpcUtils.user.promoCampaign.invalidate()
|
await trpcUtils.user.getSafely.invalidate()
|
||||||
router.refresh()
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||||
|
|
||||||
import { getIntl } from "@/i18n"
|
|
||||||
|
|
||||||
import styles from "../hero.module.css"
|
import styles from "../hero.module.css"
|
||||||
|
|
||||||
// @TODO: The ineligble message has not been finalized yet and is prone to change.
|
export default function IneligibleMessage() {
|
||||||
export default async function IneligibleMessage() {
|
const intl = useIntl()
|
||||||
const intl = await getIntl()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.ineligibleMessage}>
|
<div className={styles.ineligibleMessage}>
|
||||||
|
|||||||
@@ -76,6 +76,11 @@
|
|||||||
border-radius: 0 0 var(--card-radius) var(--card-radius);
|
border-radius: 0 0 var(--card-radius) var(--card-radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loadingCard {
|
||||||
|
background-color: var(--Surface-Brand-Accent-Default);
|
||||||
|
border-radius: 0 0 var(--card-radius) var(--card-radius);
|
||||||
|
}
|
||||||
|
|
||||||
.heading {
|
.heading {
|
||||||
color: var(--Text-Brand-OnAccent-Heading);
|
color: var(--Text-Brand-OnAccent-Heading);
|
||||||
}
|
}
|
||||||
@@ -163,7 +168,8 @@
|
|||||||
padding: var(--Space-x7) var(--Space-x3);
|
padding: var(--Space-x7) var(--Space-x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.authCard {
|
.authCard,
|
||||||
|
.loadingCard {
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
import { cx } from "class-variance-authority"
|
import { cx } from "class-variance-authority"
|
||||||
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { Divider } from "@scandic-hotels/design-system/Divider"
|
import { Divider } from "@scandic-hotels/design-system/Divider"
|
||||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||||
import Image from "@scandic-hotels/design-system/Image"
|
import Image from "@scandic-hotels/design-system/Image"
|
||||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||||
|
import { trpc } from "@scandic-hotels/trpc/client"
|
||||||
import { getProfileSafely } from "@/lib/trpc/memoizedRequests"
|
|
||||||
|
|
||||||
import { getIntl } from "@/i18n"
|
|
||||||
|
|
||||||
import ActivateOffer from "./ActivateOffer"
|
import ActivateOffer from "./ActivateOffer"
|
||||||
import IneligibleMessage from "./IneligibleMessage"
|
import IneligibleMessage from "./IneligibleMessage"
|
||||||
@@ -29,15 +29,16 @@ interface PromoCampaignHeroProps extends React.HTMLAttributes<HTMLDivElement> {
|
|||||||
promoCode: PromoCode
|
promoCode: PromoCode
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function PromoCampaignHero({
|
export default function PromoCampaignHero({
|
||||||
promoHero,
|
promoHero,
|
||||||
eligibleLevels,
|
eligibleLevels,
|
||||||
promoCode,
|
promoCode,
|
||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: PromoCampaignHeroProps) {
|
}: PromoCampaignHeroProps) {
|
||||||
const intl = await getIntl()
|
const intl = useIntl()
|
||||||
const profile = await getProfileSafely()
|
const { data: profile, isLoading: profileLoading } =
|
||||||
|
trpc.user.getSafely.useQuery()
|
||||||
|
|
||||||
const { image, heading, benefits } = promoHero
|
const { image, heading, benefits } = promoHero
|
||||||
const isLoggedIn = !!profile
|
const isLoggedIn = !!profile
|
||||||
@@ -117,7 +118,7 @@ export default async function PromoCampaignHero({
|
|||||||
<CampaignCTA />
|
<CampaignCTA />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!isLoggedIn && (
|
{!profile && !profileLoading ? (
|
||||||
<div className={cx(styles.card, styles.authCard)}>
|
<div className={cx(styles.card, styles.authCard)}>
|
||||||
<Typography
|
<Typography
|
||||||
variant="Title/Overline/sm"
|
variant="Title/Overline/sm"
|
||||||
@@ -146,7 +147,9 @@ export default async function PromoCampaignHero({
|
|||||||
</div>
|
</div>
|
||||||
<PromoSignUpButton />
|
<PromoSignUpButton />
|
||||||
</div>
|
</div>
|
||||||
)}
|
) : profileLoading ? (
|
||||||
|
<div className={cx(styles.card, styles.loadingCard)} aria-hidden />
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user