Files
web/apps/scandic-web/components/MyPages/SASLevelUpgradeCheck.tsx
Anton Gunnarsson 29f0eb4f21 Merged in feat/sw-1732-trigger-tier-match (pull request #1408)
SW-1732 Trigger SAS tier match

* Add endpoint for SAS tier match

* Add comment about future fix

* Move tier match to background request on my-pages/*

* Log result from tier match

* Clean up name etc

* Fix tier matched toast

Approved-by: Joakim Jäderberg
2025-03-13 14:12:31 +00:00

63 lines
1.7 KiB
TypeScript

"use client"
import { useEffect, useRef } from "react"
import { useIntl } from "react-intl"
import { TIER_TO_FRIEND_MAP } from "@/constants/membershipLevels"
import { trpc } from "@/lib/trpc/client"
import { toast } from "@/components/TempDesignSystem/Toasts"
export function SASLevelUpgradeCheck() {
const firedRef = useRef(false)
const intl = useIntl()
const { mutate } = trpc.partner.sas.performLevelUpgrade.useMutation({
onSuccess(result) {
switch (result.tierMatchState) {
case "matched":
toast.success(
intl.formatMessage(
{
id: "Your SAS level has upgraded you to {level}!",
},
{
level: TIER_TO_FRIEND_MAP[result.toLevel],
}
)
)
break
// TODO remove the logs, but keep for now to ease testing
case "notLinked":
console.log("[sas] not linked - this should never happen")
break
case "error":
console.log("[sas] something went wrong")
break
case "cached":
console.log("[sas] cached")
break
case "alreadyMatched":
console.log("[sas] already matched")
break
}
},
onError() {
console.log("[sas] something went wrong")
},
})
useEffect(() => {
// We must make sure this only runs once to avoid sending multiple notifications to the user.
// This aint great, but this entire thing is temporary until tier matching is event based on the server.
if (firedRef.current) {
return
}
mutate()
firedRef.current = true
}, [mutate])
return null
}