Skip to content

Commit

Permalink
wallahi its finished
Browse files Browse the repository at this point in the history
  • Loading branch information
srukelman committed Apr 18, 2024
1 parent b8a008b commit de77c37
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 141 deletions.
7 changes: 7 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AuthProvider } from './contexts/AuthContext';
import ProtectedRoute from './utils/ProtectedRoute.jsx';
import ViewBusiness from './components/ViewBusiness/ViewBusiness.jsx';
import BusinessForm from './components/BusinessForm/BusinessForm.jsx';
import ViewRequest from './components/ViewRequest/ViewRequest.jsx';

const App = () => {
return (
Expand Down Expand Up @@ -97,6 +98,12 @@ const App = () => {
path="/EditBusiness/:id"
element={<ProtectedRoute Component={BusinessForm} />}
/>
<Route
exact
path="/ViewRequest/:id"
element={<ProtectedRoute Component={ViewRequest} />}
/>

</Routes>
</div>
</div>
Expand Down
23 changes: 18 additions & 5 deletions src/components/AdminDashboard/NotificationsDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ import {
import { BellIcon, ChevronDownIcon, ArrowForwardIcon } from '@chakra-ui/icons';
import { useState } from 'react';
import DownloadCSV from '../../utils/downloadCSV';
import { useNavigate } from 'react-router-dom';


const NotificationsDrawer = ({ notificationsData }) => {
const { isOpen, onOpen, onClose } = useDisclosure();
const btnRef = React.useRef();
const [sortState, setSortState] = useState('');
const toast = useToast();
const navigate = useNavigate();

NotificationsDrawer.propTypes = {
notificationsData: PropTypes.arrayOf(
Expand Down Expand Up @@ -58,10 +61,9 @@ const NotificationsDrawer = ({ notificationsData }) => {
'Edited Information': 'Golden Scar',
};

const onActionClick = notification_type => {
console.log(notification_type);
const onActionClick = notification => {
return toast({
title: afterAction[notification_type],
title: afterAction[notification.type],
description: 'meow',
status: 'success',
duration: 9000,
Expand All @@ -81,6 +83,12 @@ const NotificationsDrawer = ({ notificationsData }) => {
DownloadCSV(headers, ids, 'notification');
};

const findBusinessId = message => {
const regex = new RegExp(`id: *[0-9]+`, 'i');
return message.match(regex, "i")[0].split(":")[1].trim();
}


return (
<>
<IconButton
Expand Down Expand Up @@ -126,9 +134,14 @@ const NotificationsDrawer = ({ notificationsData }) => {
<Text fontSize="sm">{new Date(notification.timestamp).toLocaleString()}</Text>
<Button
onClick={() => {
onActionClick(notification.type);
if (notificationAction[notification.type] === 'Download CSV')
onActionClick(notification);
if (notificationAction[notification.type] === 'Download CSV') {
handleDownloadCSV([notification.notification_id]);
} else if (notificationAction[notification.type] === 'View Request') {
navigate(`/ViewRequest/${findBusinessId(notification.message)}`);
} else if (notificationAction[notification.type] === 'View Application' || notificationAction[notification.type] === 'View Information') {
navigate(`/ViewBusiness/${findBusinessId(notification.message)}`);
}
}}
rightIcon={<ArrowForwardIcon />}
>
Expand Down
175 changes: 39 additions & 136 deletions src/components/ContactUsForm/ContactUs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,19 @@ const ContactUs = () => {
const { backend } = useBackend();
const navigate = useNavigate();
const [text, setText] = useState('');
const [checkedItems, setCheckedItems] = useState([0, 0, 0, 0, 0, 0, 0]);
const [checkedItems, setCheckedItems] = useState([0, 0, 0, 0, 0, 0, 0, 0]);
const [showConfirmation, setShowConfirmation] = useState(false);
const [isFormValid, setIsFormValid] = useState(false);
const checkedThingies = [
'Get Pet Food Decal',
'Decal',
'Homeless Card',
'Business Card',
'Donation Site Decal',
'Donation Site Bin Decals',
'Donation Envelopes',
'Homeless Card 2'
];

const formData = {
business_id: business_ID,
Expand Down Expand Up @@ -82,11 +92,11 @@ const ContactUs = () => {
const updatedFormData = {
...formData,
message: message,
type: 'Supply Request',
timestamp: new Date().toLocaleString('en-US', {
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
}),
been_dismissed: false,
type: 'Supply Request Received',
};
await backend.post('/notification/', updatedFormData);
setShowConfirmation(true);
Expand All @@ -108,25 +118,12 @@ const ContactUs = () => {

const setMessage = text => {
const textCopy = text;
const checkedThingies = [
'DS Decals',
'Rack Cards',
'Donation Envelopes',
'Business Cards',
'Stickers',
'Bin Decals',
'DS Decals',
];
const preMessage = `Business ID: ${senderID} is requesting:
${checkedThingies[0]}: ${checkedItems[0]}
${checkedThingies[1]}: ${checkedItems[1]}
${checkedThingies[2]}: ${checkedItems[2]}
${checkedThingies[3]}: ${checkedItems[3]}
${checkedThingies[4]}: ${checkedItems[4]}
${checkedThingies[5]}: ${checkedItems[5]}
${checkedThingies[6]}: ${checkedItems[6]}\n`; // business name... hard-coded right now
const updatedMessage = checkedThingies.filter((_, index) => checkedItems[index]).join('\n-');
return `${preMessage}-${updatedMessage}\nNotes:\n${textCopy}`;

const preMessage = `Business ID: ${senderID} is requesting:`;
const messageBody = checkedThingies.map((item, index) => (
`${item}: ${checkedItems[index]}\n`
));
return `${preMessage}\n${messageBody}\nNotes:\n${textCopy}`;
};

const textInputHandler = e => {
Expand Down Expand Up @@ -171,121 +168,27 @@ const ContactUs = () => {
borderRightRadius="1"
>
<Stack>
<HStack marginBottom={'17%'}>
<NumberInput
size="sm"
maxW={20}
defaultValue={0}
min={0}
onChange={e => handleNumInputChange(e, 0)}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
<Text>DS Decals</Text>
</HStack>
<HStack marginBottom={'17%'}>
<NumberInput
size="sm"
maxW={20}
defaultValue={0}
min={0}
onChange={e => handleNumInputChange(e, 1)}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
<Text>Rack Cards</Text>
</HStack>
<HStack marginBottom={'17%'}>
<NumberInput
size="sm"
maxW={20}
defaultValue={0}
min={0}
onChange={e => handleNumInputChange(e, 2)}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
<Text>Donation Envelopes</Text>
</HStack>
<HStack marginBottom={'17%'}>
<NumberInput
size="sm"
maxW={20}
defaultValue={0}
min={0}
onChange={e => handleNumInputChange(e, 3)}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
<Text>BusinessCards</Text>
</HStack>
<HStack marginBottom={'17%'}>
<NumberInput
size="sm"
maxW={20}
defaultValue={0}
min={0}
onChange={e => handleNumInputChange(e, 4)}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
<Text>Stickers</Text>
</HStack>
</Stack>
<Stack margin={'5%'}></Stack>
<Stack>
<HStack marginBottom={'17%'}>
<NumberInput
size="sm"
maxW={20}
defaultValue={0}
min={0}
onChange={e => handleNumInputChange(e, 5)}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
<Text>Bin Decals</Text>
</HStack>
<HStack marginBottom={'17%'}>
<NumberInput
size="sm"
maxW={20}
defaultValue={0}
min={0}
onChange={e => handleNumInputChange(e, 6)}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
<Text>DS Decals</Text>
</HStack>
{checkedThingies.map((item, index) => (
<HStack
marginBottom={'17%'}
key={index}
>
<NumberInput
size="sm"
maxW={20}
defaultValue={0}
min={0}
onChange={e => handleNumInputChange(e, index)}
>
<NumberInputField />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
<Text>{item}</Text>
</HStack>
))}
</Stack>
</Box>
</Card>
Expand Down
Loading

0 comments on commit de77c37

Please sign in to comment.