Skip to content

Commit

Permalink
Merge pull request #221 from Sahil-Connect/SAH-100
Browse files Browse the repository at this point in the history
[SAH-100]: Split Account page into two pages (Account & Billing)
  • Loading branch information
Emmanuel-Melon authored Nov 19, 2024
2 parents 5a4cf81 + e8b9b29 commit 3570d73
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 132 deletions.
7 changes: 6 additions & 1 deletion apps/client/src/Layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
HiOutlineBriefcase,
HiOutlineUserCircle,
HiOutlineTruck,
HiOutlineBuildingOffice,
HiOutlineCreditCard,
} from "react-icons/hi2";

const links = [
Expand All @@ -29,6 +29,11 @@ const links = [
href: "/account",
icon: HiOutlineUserCircle,
},
{
name: "Billing",
href: "/billing",
icon: HiOutlineCreditCard,
}
];

export default function Layout({ children, ...props }: LayoutProps) {
Expand Down
131 changes: 0 additions & 131 deletions apps/client/src/pages/account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default function Account() {
// @ts-ignore
business && <BusinessProfileOverview business={business} />
}
<MomoAccountDetails />
</div>
<div className="basis-4/5 space-y-2">
<BusinessOrderHistory />
Expand All @@ -46,136 +45,6 @@ export default function Account() {
);
}

const MomoAccountDetails = () => {
return (
<Card>
<h3 className="text-xl">Momo Account Details</h3>
<MomoUserInfo />
<MomoAccountBalance />
</Card>
);
};

const MomoUserInfo = () => {
// const { data, loading, refetch } = useGetMomoAccountInfo();
// const [isRefetching, setIsRefetching] = useState(false);

// const handleRefetch = async () => {
// if (!isRefetching) {
// setIsRefetching(true);
// await refetch().then(() => setIsRefetching(false));
// }
// };
return (
<Card>
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-2 xl:grid-cols-4 gap-2">
<div>
<p className="text-gray-400 text-sm">Given Name</p>
{/* {loading ? (
<div className="w-12 h-4 bg-base-200 animate-pulse" />
) : (
<p>{data?.given_name}</p>
)} */}
</div>
<div>
<p className="text-gray-400 text-sm">Family Name</p>
{/* {loading ? (
<div className="w-12 h-4 bg-base-200 animate-pulse" />
) : (
<p>{data?.family_name}</p>
)} */}
</div>
<div>
<p className="text-gray-400 text-sm">Gender</p>
{/* {loading ? (
<div className="w-12 h-4 bg-base-200 animate-pulse" />
) : (
<p>{data?.gender}</p>
)} */}
</div>
<div>
<p className="text-gray-400 text-sm">Status</p>
{/* {loading ? (
<div className="w-12 h-4 bg-base-200 animate-pulse" />
) : (
<p>{data?.status || "Active"}</p>
)} */}
</div>
</div>
{/* {data === null && (
<div className="card-actions flex-col">
<p>
{isRefetching
? "Refetching account info..."
: "Couldn't fetch account info."}
</p>
<button
onClick={handleRefetch}
className={`btn btn-sm btn-secondary ${
isRefetching && "animate-pulse"
}`}
>
Reload
</button>
</div>
)} */}
</Card>
);
};

const MomoAccountBalance = () => {
// const { data, loading, refetch } = useGetAccountBalance();
const [isRefetching, setIsRefetching] = useState(false);

// const handleRefetch = async () => {
// if (!isRefetching) {
// setIsRefetching(true);
// await refetch().then(() => setIsRefetching(false));
// }
// };

return (
<Card>
<p>Hello</p>
{/* <div className="grid grid-cols-2 gap-2">
<div>
<p className="text-gray-400 text-sm">Currency</p>
{loading ? (
<div className="w-12 h-4 bg-base-200 animate-pulse" />
) : (
<p>{data?.currency}</p>
)}
</div>
<div>
<p className="text-gray-400 text-sm">Balance</p>
{loading ? (
<div className="w-12 h-4 bg-base-200 animate-pulse" />
) : (
<p>{data?.availableBalance}</p>
)}
</div>
</div>
{data === null && (
<div className="card-actions flex-col">
<p>
{isRefetching
? "Refetching balance..."
: "Couldn't fetch account balance."}
</p>
<button
onClick={handleRefetch}
className={`btn btn-sm btn-secondary ${
isRefetching && "animate-pulse"
}`}
>
Reload
</button>
</div>
)} */}
</Card>
);
};

const TransactionsHistory = () => {
const transactions = [
{
Expand Down
102 changes: 102 additions & 0 deletions apps/client/src/pages/billing/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { HiOutlineCurrencyDollar, HiOutlineCreditCard, HiOutlineDocumentText, HiPlus } from "react-icons/hi2";
import { Card } from "ui";
import { useState } from "react";

const PaymentMethodCard = ({ method, isPreferred, onEdit, onSetPreferred }) => (
<Card className="mb-4">
<div className="flex items-center justify-between p-2">
<div>
<span className="font-medium">{method.type} ending in {method.last4}</span>
{isPreferred && <span className="ml-2 text-sm text-green-600">Preferred</span>}
</div>
<div>
<button onClick={onEdit} className="text-blue-600 hover:underline mr-2">Edit</button>
{!isPreferred && (
<button onClick={onSetPreferred} className="text-green-600 hover:underline">Set as Preferred</button>
)}
</div>
</div>
</Card>
);

export default function Billing() {
const [paymentMethods, setPaymentMethods] = useState([
{ id: 1, type: 'Visa', last4: '1234' },
{ id: 2, type: 'Mastercard', last4: '5678' },
]);
const [preferredMethodId, setPreferredMethodId] = useState(1);

const handleAddPaymentMethod = () => {
// Implement add payment method logic
};

const handleEditPaymentMethod = (id) => {
// Implement edit payment method logic
};

const handleSetPreferred = (id) => {
setPreferredMethodId(id);
};

return (
<div className="max-w-6xl mx-auto p-4">
<h1 className="text-2xl font-bold mb-6">Billing</h1>
<div className="flex flex-col md:flex-row gap-6">
<div className="md:w-1/3">
<h2 className="text-xl font-semibold mb-4 flex items-center">
<HiOutlineCreditCard className="mr-2" /> Payment Methods
</h2>
{paymentMethods.map((method) => (
<PaymentMethodCard
key={method.id}
method={method}
isPreferred={method.id === preferredMethodId}
onEdit={() => handleEditPaymentMethod(method.id)}
onSetPreferred={() => handleSetPreferred(method.id)}
/>
))}
<button
onClick={handleAddPaymentMethod}
className="btn btn-primary w-full flex items-center justify-center"
>
<HiPlus className="mr-2" /> Add Payment Method
</button>
</div>
<div className="md:w-2/3">
<div className="space-y-6">
<section className="border-b pb-4">
<h2 className="text-xl font-semibold mb-2 flex items-center">
<HiOutlineCurrencyDollar className="mr-2" /> Summary
</h2>
<div className="grid grid-cols-2 gap-4">
<div>
<span className="block text-sm font-medium text-gray-700">Total Earned</span>
<span className="text-2xl font-bold">$1,234.56</span>
</div>
<div>
<span className="block text-sm font-medium text-gray-700">Total Spent</span>
<span className="text-2xl font-bold">$567.89</span>
</div>
</div>
</section>
<section>
<h2 className="text-xl font-semibold mb-2 flex items-center">
<HiOutlineDocumentText className="mr-2" /> Recent Transactions
</h2>
<ul className="space-y-2">
<li className="flex justify-between items-center">
<span>Product Sale</span>
<span className="text-green-600">+$50.00</span>
</li>
<li className="flex justify-between items-center">
<span>Platform Fee</span>
<span className="text-red-600">-$5.00</span>
</li>
</ul>
</section>
</div>
</div>
</div>
</div>
);
}
1 change: 1 addition & 0 deletions packages/features/auth/lib/handleDecryptToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function handleDecryptToken(
return async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
const payload = await getIdTokenClaims(req);
console.log("payload", payload);
if (!payload) {
res.status(401).json({ message: "Unauthorized" });
return;
Expand Down

0 comments on commit 3570d73

Please sign in to comment.