diff --git a/apps/dashboard/src/components/settings/Account/Billing/ApplyCouponCard.stories.tsx b/apps/dashboard/src/components/settings/Account/Billing/ApplyCouponCard.stories.tsx index 26eb55f1627..9bf79a07d61 100644 --- a/apps/dashboard/src/components/settings/Account/Billing/ApplyCouponCard.stories.tsx +++ b/apps/dashboard/src/components/settings/Account/Billing/ApplyCouponCard.stories.tsx @@ -54,6 +54,14 @@ function statusStub(status: number) { function Story() { return (
+ + + + void; }) { + const searchParams = useSearchParams(); + const couponCode = searchParams?.get("coupon"); return ( { const res = await fetch("/api/server-proxy/api/v1/coupons/redeem", { method: "POST", @@ -79,14 +84,30 @@ export function ApplyCouponCardUI(props: { data: null | ActiveCouponResponse; }>; onCouponApplied: ((data: ActiveCouponResponse) => void) | undefined; + prefillPromoCode?: string; + scrollIntoView?: boolean; }) { + const containerRef = useRef(null); const form = useForm>({ resolver: zodResolver(couponFormSchema), defaultValues: { - promoCode: "", + promoCode: props.prefillPromoCode, }, }); + const scrolled = useRef(false); + // eslint-disable-next-line no-restricted-syntax + useEffect(() => { + if (props.scrollIntoView && !scrolled.current) { + const el = containerRef.current; + if (el) { + el.scrollIntoView({ behavior: "smooth", block: "start" }); + el.querySelector("input")?.focus(); + scrolled.current = true; + } + } + }, [props.scrollIntoView]); + const applyCoupon = useMutation({ mutationFn: (promoCode: string) => props.submit(promoCode), }); @@ -133,7 +154,7 @@ export function ApplyCouponCardUI(props: { return (
- + - -
- ); + return ; } const couponData = optimisticCouponData @@ -296,17 +313,27 @@ export function CouponSection(props: { teamId: string | undefined }) { } return ( - { - setOptimisticCouponData({ - type: "added", - data: coupon, - }); - activeCoupon.refetch().then(() => { - setOptimisticCouponData(undefined); - }); - }} - /> + }> + { + setOptimisticCouponData({ + type: "added", + data: coupon, + }); + activeCoupon.refetch().then(() => { + setOptimisticCouponData(undefined); + }); + }} + /> + + ); +} + +function LoadingCouponSection() { + return ( +
+ +
); }