Skip to content

Commit

Permalink
Merge pull request #143 from Blueprint-Boulder/photoIntegration
Browse files Browse the repository at this point in the history
Photo integration
  • Loading branch information
nh602 authored May 22, 2024
2 parents f90cbb5 + 0b69033 commit 1f65a12
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 156 deletions.
7 changes: 4 additions & 3 deletions backend/controllers/EventController.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ const getAttendingVendors = async (req, res, next) => {
const vendors = await db.manyOrNone(`
SELECT
V.vendor_id,
V.name AS vendor_name,
V.name,
V.phone_number,
V.website,
V.email
V.email,
V.image
FROM
Vendors V
vendor_full V
JOIN
EventRequests ER ON V.vendor_id = ER.vendor_id
WHERE
Expand Down
Binary file added frontend/public/profile.webp
Binary file not shown.
37 changes: 37 additions & 0 deletions frontend/src/components/EventVendorsDisplay.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import VendorEventCard from './VendorEventCard';

export default function EventVendorsDisplay({showApproved, requests, vendors, eventService}) {
const createCardsAdmin = (reqs) => {
console.log('create cards admin');
return reqs.map((req) => {
console.log('Request:', req);
console.log('Vendors:', vendors);

if (vendors.length === 0) return <></>;
if (showApproved === true && req.approved !== true) return <></>;
// if (showApproved === false && req.approved !== null) return <></>;


// Fetch the vendor's profile
const res = vendors.filter((v) => v.id === req.vendorId)[0];
console.log('Vendor:', res);

// Return the card
return <VendorEventCard key={res.id} vendor={res} request={req} eventService={eventService}></VendorEventCard>;
});
};

const createCards = (vends) => {
console.log('create cards');
return vends.map((vendor)=> {
return <VendorEventCard key={vendor.id} vendor={vendor} request={undefined} eventService={eventService}></VendorEventCard>;
});
};

return <div className='flex flex-wrap p-10'>
{
requests.length > 0 ? createCardsAdmin(requests) : createCards(vendors)
}
</div>;
}
55 changes: 55 additions & 0 deletions frontend/src/components/VendorEventCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, {useContext} from 'react';

import {Context} from '../services/context';


export default function VendorEventCard({vendor, request, eventService}) {
const {user, setMessage, setBad} = useContext(Context);


console.log('LoadingCard:', vendor, request);

// Sets approved to value
const updateRequest = async (value) => {
const res = await eventService.updateEventRequest(vendor.id, {approved: value});
if (!res) {
setMessage('Failed to update vendor request for event.');
setBad(true);
} else {
// Should be checking the res status before saying this succeeded?
setMessage('Vendor request updated for event.');
}
window.location.reload();
};

const AdminButtons = () => {
if (user && user.isadmin) {
if (request && request.approved) { // Show buttons to reject or set to pending
return <div className='flex flex-row spacing-3'>
<button className='mt-3 text-gray-800 font-semibold drop-shadow-xl rounded-md bg-white w-24 click:text-white' onClick={() => updateRequest(false)}>Reject Request</button>
<button className='mt-3 text-gray-800 font-semibold drop-shadow-xl rounded-md bg-white w-24 click:text-white' onClick={() => updateRequest(undefined)}>Set Pending</button>
</div>;
} else { // Show buttons to reject or approve
return <div className='flex flex-row spacing-3'>
<button className='mt-3 text-gray-800 font-semibold drop-shadow-xl rounded-md bg-white w-24 click:text-white' onClick={() => updateRequest(true)}>Approve</button>
<button className='mt-3 text-gray-800 font-semibold drop-shadow-xl rounded-md bg-white w-24 click:text-white' onClick={() => updateRequest(false)}>Reject Request</button>
</div>;
}
} else { // Only admins need buttons to manage event requests
return <></>;
}
};

console.log('vendreq', request);
console.log('vendvend', vendor);

return (
<div className='flex flex-col p-10 basis-1/2 items-center'>
<img src={vendor.image ? `/profilepics/${vendor.image}` : '/profile.webp'}></img>
<p className='text-center'>{vendor.name}</p>
{
<AdminButtons></AdminButtons>
}
</div>
);
}
9 changes: 9 additions & 0 deletions frontend/src/objects/User.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {jwtDecode} from 'jwt-decode';
import Cookies from 'js-cookie';
/*
Storage mechanism for the currently logged-in user.
*/
Expand All @@ -18,4 +19,12 @@ export default class User {
if ('admin_id' in decode) return new User(decode.admin_id, decode.name, decode.email, true, null, null);
return new User(decode.vendor_id, decode.name, decode.email, false, decode.phone_number, decode.website);
}

static getLoggedInUser() {
const cookie = Cookies.get('auth') || Cookies.get('auth_pim');
if (cookie !== undefined) {
return this.newUserFromCookie(cookie);
}
return undefined;
}
}
Loading

0 comments on commit 1f65a12

Please sign in to comment.