2024-06-04 22:59:02 -04:00
|
|
|
"use client";
|
|
|
|
import { createClient } from "@/utils/supabase/client";
|
2024-06-08 00:26:23 -04:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { useRouter } from 'next/navigation';
|
2024-06-04 22:59:02 -04:00
|
|
|
|
|
|
|
function PageComponent() {
|
2024-06-08 00:26:23 -04:00
|
|
|
const router = useRouter();
|
|
|
|
const supabase = createClient();
|
|
|
|
const [tiers, setTiers] = useState<any[]>([]);
|
|
|
|
const getData = async () => {
|
|
|
|
try {
|
|
|
|
const response = await fetch('/api/tiers');
|
|
|
|
if (response.ok) {
|
|
|
|
const data = await response.json();
|
|
|
|
setTiers(data);
|
|
|
|
} else {
|
2024-06-08 19:43:26 -04:00
|
|
|
console.error('failed to fetch tiers');
|
2024-06-08 00:26:23 -04:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error fetching users:', error);
|
|
|
|
}
|
2024-06-04 22:59:02 -04:00
|
|
|
}
|
|
|
|
|
2024-06-08 00:26:23 -04:00
|
|
|
useEffect(() => {
|
|
|
|
getData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="w-2/3 p-8 h-1/2 text-white lg:flex justify-center items-center animate-in">
|
2024-06-08 19:13:54 -04:00
|
|
|
<div className="w-full lg:w-1/3 rounded-md bg-primary opacity-90 p-8 m-1 mt-32 shadow-lg backdrop-blur">
|
2024-06-08 00:26:23 -04:00
|
|
|
<div className="w-full flex justify-center">
|
|
|
|
<span className="text-2xl pb-4">Tiers Management</span>
|
|
|
|
</div>
|
|
|
|
<div className="w-full flex justify-center">
|
|
|
|
<button onClick={() => { router.push("/admin/tiers/create") }} className="bg-success hover:bg-success-light rounded p-2 w-full">New Tier</button>
|
|
|
|
<button onClick={() => { router.push("/admin") }} className="bg-error hover:bg-error-light rounded p-2 w-full ml-2">Back</button>
|
|
|
|
</div>
|
|
|
|
<div className="w-full justify-center pt-8">
|
|
|
|
{tiers.map((item, index) => (
|
|
|
|
<div className="w-full flex justify-center">
|
|
|
|
<div key={index} className="text-white w-full text-stroke mt-2">
|
|
|
|
<button onClick={() => { router.push("/admin/tiers/view?name=" + item.name) }} className="py-2 w-full rounded hover:scale-105" style={{ backgroundColor: item.color }}>{item.name} - ${item.price}/month</button>
|
|
|
|
</div>
|
2024-06-04 22:59:02 -04:00
|
|
|
</div>
|
2024-06-08 00:26:23 -04:00
|
|
|
))}
|
|
|
|
</div>
|
2024-06-04 22:59:02 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-08 00:26:23 -04:00
|
|
|
);
|
2024-06-04 22:59:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PageComponent;
|
|
|
|
|
|
|
|
|
|
|
|
|