SW-2232 Adapt SAS router to API changes * Adapt sas procedures to api changes * Remove debug logs * Capture performLevelUpgrade error * More sentry logging * Merge branch 'master' into feat/sw-2232-sas-api-updates Approved-by: Joakim Jäderberg
48 lines
1.2 KiB
TypeScript
48 lines
1.2 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) {
|
|
if (result.tierMatchState === "matched") {
|
|
toast.success(
|
|
intl.formatMessage(
|
|
{
|
|
defaultMessage: "Your SAS level has upgraded you to {level}!",
|
|
},
|
|
{
|
|
level: TIER_TO_FRIEND_MAP[result.toLevel],
|
|
}
|
|
)
|
|
)
|
|
}
|
|
},
|
|
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
|
|
}
|