Updated it so the Corporate is updated into Active when its payment is accepted

This commit is contained in:
Tiago Ribeiro
2024-01-21 20:35:35 +00:00
parent 8c1da3a84a
commit cfde8ac9f0
3 changed files with 7 additions and 1 deletions

View File

@@ -74,6 +74,10 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
if (user.type === "admin" || user.type === "developer") { if (user.type === "admin" || user.type === "developer") {
await setDoc(snapshot.ref, req.body, {merge: true}); await setDoc(snapshot.ref, req.body, {merge: true});
if (req.body.isPaid) {
const corporateID = req.body.corporate;
await setDoc(doc(db, "users", corporateID), {status: "active"}, {merge: true});
}
return res.status(200).json({ok: true}); return res.status(200).json({ok: true});
} }

View File

@@ -119,6 +119,8 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
const updatedDoc = (await getDoc(doc(db, "payments", paymentId))).data() as Payment; const updatedDoc = (await getDoc(doc(db, "payments", paymentId))).data() as Payment;
if (updatedDoc.commissionTransfer && updatedDoc.corporateTransfer) { if (updatedDoc.commissionTransfer && updatedDoc.corporateTransfer) {
await setDoc(doc(db, "payments", paymentId), {isPaid: true}, {merge: true}); await setDoc(doc(db, "payments", paymentId), {isPaid: true}, {merge: true});
await setDoc(doc(db, "users", updatedDoc.corporate), {status: "active"}, {merge: true});
} }
res.status(200).json({ref}); res.status(200).json({ref});
} catch (error) { } catch (error) {

View File

@@ -111,7 +111,7 @@ const PaymentCreator = ({onClose, reload, showComission = false}: {onClose: () =
options={(users.filter((u) => u.type === "corporate") as CorporateUser[]).map((user) => ({ options={(users.filter((u) => u.type === "corporate") as CorporateUser[]).map((user) => ({
value: user.id, value: user.id,
meta: user, meta: user,
label: `${user.corporateInformation.companyInformation.name || user.name} - ${user.email}`, label: `${user.corporateInformation?.companyInformation?.name || user.name} - ${user.email}`,
}))} }))}
defaultValue={{value: "undefined", label: "Select an account"}} defaultValue={{value: "undefined", label: "Select an account"}}
onChange={(value) => setCorporate((value as any)?.meta ?? undefined)} onChange={(value) => setCorporate((value as any)?.meta ?? undefined)}