mirror of
https://github.com/harivansh-afk/Saas-Teamspace.git
synced 2026-04-15 04:03:31 +00:00
25 lines
679 B
TypeScript
25 lines
679 B
TypeScript
'use client'
|
|
import axios from 'axios'
|
|
import { useState } from 'react'
|
|
import toast from 'react-hot-toast'
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
export const PurchaseButton = () => {
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
const onClick = async () => {
|
|
try {
|
|
setIsLoading(true)
|
|
const response = await axios.post('/api/checkout')
|
|
window.location.href = response.data.url
|
|
} catch (error) {
|
|
toast.error('An error occurred. Please try again.')
|
|
} finally {
|
|
setIsLoading(false)
|
|
}
|
|
}
|
|
return (
|
|
<Button onClick={onClick} disabled={isLoading}>
|
|
{isLoading ? 'Loading...' : 'Purchase'}
|
|
</Button>
|
|
)
|
|
}
|