Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/DonationHistoryContent/DonationsList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAuth } from "@/context/AuthContext";
import { getInvoicesByUid } from "@/services/firebase/invoiceService";
import { getInvoicesByEmail } from "@/services/firebase/invoiceService";
import { Invoice } from "@/types/invoice";
import React, { useEffect, useState } from "react";
import Loading from "../Loading";
Expand All @@ -13,7 +13,7 @@ export const DonationsList = () => {
useEffect(() => {
const fetchInvoices = async () => {
setLoading(true);
const invoices = await getInvoicesByUid(user?.uid || "");
const invoices = await getInvoicesByEmail(user?.email || "");
setInvoices(invoices);
setLoading(false);
};
Expand Down
1 change: 1 addition & 0 deletions src/components/GoogleSignInButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const GoogleSignInButton: React.FC<GoogleSignInButtonProps> = ({ onError }) => {
try {
onError("");
const provider = new GoogleAuthProvider();
provider.addScope('email');
await signInWithPopup(auth, provider);
router.push("/my/account");
} catch {
Expand Down
21 changes: 20 additions & 1 deletion src/components/OnboardingForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { countries } from "@/utils/constant/countries";

const OnboardingForm: React.FC = () => {
const { user, loading } = useAuth();
console.log(user);
const { onboarded } = useMy();
const router = useRouter();
const [email, setEmail] = useState(user?.email || "");
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [phoneNumber, setPhoneNumber] = useState("");
Expand All @@ -24,6 +24,7 @@ const OnboardingForm: React.FC = () => {
const isDisabled =
!firstName ||
!lastName ||
!email ||
!phoneNumber ||
!address ||
!city ||
Expand All @@ -41,6 +42,7 @@ const OnboardingForm: React.FC = () => {
const profile = await getUserProfile(user.uid);
if (profile) {
setFirstName(profile.firstName || "");
setEmail(profile.email || "");
setLastName(profile.lastName || "");
setPhoneNumber(profile.phoneNumber || "");
setAddress(profile.address || "");
Expand Down Expand Up @@ -68,6 +70,7 @@ const OnboardingForm: React.FC = () => {
await updateUserProfile(user.uid, {
firstName,
lastName,
email,
phoneNumber,
address,
city,
Expand Down Expand Up @@ -128,6 +131,22 @@ const OnboardingForm: React.FC = () => {
value={lastName}
onChange={(e) => setLastName(e.target.value)}
/>
</div>
<div>
<label htmlFor="email" className="sr-only">
Email Address
</label>
<input
id="email"
name="email"
type="email"
autoComplete="email"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-primary-500 focus:border-primary-500 focus:z-10 sm:text-sm"
placeholder="Email Address"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div>
<label htmlFor="phone-number" className="sr-only">
Expand Down
16 changes: 16 additions & 0 deletions src/services/firebase/invoiceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ export const getInvoicesByUid = async (uid: string): Promise<Invoice[]> => {
});
return invoices;
};

export const getInvoicesByEmail = async (email: string): Promise<Invoice[]> => {
const invoicesRef = collection(db, "invoices");
const q = query(
invoicesRef,
where("payer_email", "==", email),
orderBy("paid_at", "desc"),
);
const snapshot = await getDocs(q);
const invoices: Invoice[] = snapshot.docs.map((d) => {
const data = d.data() as Invoice;
// Ensure the returned object contains the Firestore doc id
return { ...data, id: d.id };
});
return invoices;
};
4 changes: 2 additions & 2 deletions src/utils/constant/donation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const presetAmounts = [
500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500,
7000, 7500, 8000, 8500, 9000, 9500, 10000,
100, 200, 300, 400, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000,
5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000,
];