Skip to content

Commit

Permalink
more updates for selfservice
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbliss committed Nov 13, 2024
1 parent 7e48928 commit 8d463fb
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 202 deletions.
131 changes: 67 additions & 64 deletions src/components/CommunityPane.jsx
Original file line number Diff line number Diff line change
@@ -1,98 +1,101 @@

import { Typography } from "@mui/material";

import HeaderBox from "./HeaderBox";
import ScoreSection from './ScoreSection';
import Pane from './Pane';
import Section from './Section';

import { Box, Stack } from '@mui/material';

import theme from '../theme';


const getSectionData = community => [
const getSectionData = (community, isSelectable, availableOptions, onSelectionChange) => [
{
header: 'State',
cards: [ community.state ]
cards: community.state,
availableSelections: isSelectable ? availableOptions?.state || [] : [],
},
{
header: 'Activities',
cards: community.activities
cards: community.activities,
availableSelections: isSelectable ? availableOptions?.activities || [] : [],
},
{
header: 'Sectors',
cards: community.sectors
cards: community.sectors,
availableSelections: isSelectable ? availableOptions?.sectors || [] : [],
},
{
header: 'Hazards',
cards: community.hazards
cards: community.hazards,
availableSelections: isSelectable ? availableOptions?.hazards || [] : [],
},
{
header: 'Size',
cards: [ community.size ]
cards: community.size,
availableSelections: isSelectable ? availableOptions?.size || [] : [],
}
]
.map((section, index) => {
].map((section, index) => {
section.type = 'community'
section.key=`section${index}`
section.key = `section${index}`
section.isSelectable = isSelectable
section.onSelectionChange = onSelectionChange
return section
});

export default function CommunityPane({
community,
isSelectable = false,
availableOptions = {},
onSelectionChange = () => {}
}) {
const sectionData = getSectionData(community, isSelectable, availableOptions, onSelectionChange);

export default function CommunityPane({ community }) {
const sectionData = getSectionData(community);
return (
<Box
sx={{
bgcolor: 'primary.white',
borderRadius: 4,
border: `0px solid ${theme.palette.primary.white}`,
pr: 1,
pl: 1,
pt: 0,
pb: 1,
}}
>
<Stack
sx={{ width: '100%' }}>
<HeaderBox>
<Typography
color="primary.main"
fontWeight="700"
align="center"
variant="h5"
sx={{
fontSize: {
'xs': '1rem',
'lg': '1.5rem',
}
}}
>{ community.name }</Typography>
</HeaderBox>
{ /* filler box to match height of "Matched Practitioners" heading */ }
<Box sx={{ height: '40px', width: '100%', }}></Box>
</Stack>
<Pane
boxShadow={2}
sx={{ pl: 1 }}>
{
sectionData.map((section, index) => {
return Section(section)
})
}
<ScoreSection
<Box
sx={{
pr: 2,
bgcolor: 'primary.white',
borderRadius: 4,
border: `0px solid ${theme.palette.primary.white}`,
pr: 1,
pl: 1,
justifyContent: 'space-between',
}}
pt: 0,
pb: 1,
}}
>
<Stack sx={{ width: '100%' }}>
<HeaderBox>
<Typography
color="primary.main"
fontWeight="700"
align="center"
variant="h5"
sx={{
fontSize: {
'xs': '1rem',
'lg': '1.5rem',
}
}}
>{community.name}</Typography>
</HeaderBox>
{/* filler box to match height of "Matched Practitioners" heading */}
<Box sx={{ height: '40px', width: '100%', }}></Box>
</Stack>
<Pane
boxShadow={2}
sx={{ pl: 1 }}
>
<div>Total</div>
<div>{ community.totalCategories }</div>
</ScoreSection>
</Pane>
</Box>
{sectionData.map((section, index) => {
return Section(section)
})}
<ScoreSection
sx={{
pr: 2,
pl: 1,
justifyContent: 'space-between',
}}
>
<div>Total</div>
<div>{community.totalCategories}</div>
</ScoreSection>
</Pane>
</Box>
)
}

79 changes: 63 additions & 16 deletions src/components/DropDownSelector.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import theme from '../theme';

const DropDownSelector = (props) => {
const { availableSelections, selections, setSelections, option } = props;
const DropDownSelector = ({ availableSelections, selections, setSelections, option }) => {
const [isDropdownOpen, setIsDropdownOpen] = useState(false);

const handleAdd = (itemToAdd) => {
Expand All @@ -17,45 +17,92 @@ const DropDownSelector = (props) => {

return (
<div className="flex flex-col gap-2">
<div className="font-medium text-gray-700">{option}</div>

{/* Selected States */}
{/* Selected Items */}
<div className="flex flex-col gap-2">
{selections.map((item) => (
<div
key={item}
className="flex items-center justify-between px-3 py-2 bg-amber-50 rounded"
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
padding: '8px 12px',
backgroundColor: theme.palette.primary.tan,
borderRadius: '4px',
}}
>
<span>{item}</span>
<span style={{ color: theme.palette.primary.main }}>{item}</span>
<button
onClick={() => handleRemove(state)}
className="text-gray-500 hover:text-gray-700"
onClick={() => handleRemove(item)}
style={{
color: theme.palette.primary.main,
border: 'none',
background: 'none',
fontSize: '18px',
cursor: 'pointer',
padding: '0 4px'
}}
>
×
</button>
</div>
))}
</div>

{/* Add State Button & Dropdown */}
{/* Add Button & Dropdown */}
<div className="relative">
<button
onClick={() => setIsDropdownOpen(!isDropdownOpen)}
className="flex items-center gap-2 px-3 py-2 text-blue-600 bg-blue-100 rounded hover:bg-blue-200"
style={{
display: 'flex',
alignItems: 'center',
gap: '8px',
padding: '8px 12px',
color: theme.palette.primary.midBlue,
backgroundColor: theme.palette.primary.lightBlue,
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
width: '100%'
}}
>
<span className="text-lg">+</span>
Add another {option}
<span style={{ fontSize: '20px' }}>+</span>
{selections.length === 0 ? `Add ${option}` : `Add another ${option}`}
</button>

{isDropdownOpen && (
<div className="absolute z-10 w-full mt-1 bg-white border border-gray-200 rounded-md shadow-lg max-h-60 overflow-auto">
<div
style={{
position: 'absolute',
zIndex: 10,
width: '100%',
marginTop: '4px',
backgroundColor: theme.palette.primary.white,
border: `1px solid ${theme.palette.primary.borderGray}`,
borderRadius: '4px',
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
maxHeight: '240px',
overflowY: 'auto'
}}
>
{availableSelections
.filter(item => !selections.includes(item))
.map((item) => (
<button
key={item}
onClick={() => handleAdd(item)}
className="w-full px-4 py-2 text-left hover:bg-gray-100"
style={{
width: '100%',
padding: '8px 16px',
textAlign: 'left',
border: 'none',
background: 'none',
cursor: 'pointer',
color: theme.palette.primary.main,
':hover': {
backgroundColor: theme.palette.primary.lightGray
}
}}
>
{item}
</button>
Expand All @@ -67,4 +114,4 @@ const DropDownSelector = (props) => {
);
};

export default DropDownSelector;
export default DropDownSelector;
43 changes: 32 additions & 11 deletions src/components/Section.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@

import { Typography, Box, Stack } from "@mui/material"

import Cell from "./Cell"
import DropDownSelector from "./DropDownSelector"
import theme from '../theme'

export default function Section ({ header='', type, cards, key }) {
export default function Section({ header='', type, cards, key, isSelectable, onSelectionChange, availableSelections = [] }) {
const cells = cards.map((label, index) => Cell({ label, type, key: `${key}_row${index}` }))

return (
<Box key={ key } sx={{ mb: 2 }}>
<Box sx={{ minHeight: '40px', mt: '5px', mb: '5px' }}>
<Typography variant="body1" >{ header }</Typography>
<Box key={key} sx={{ mb: 2 }}>
{/* Section Header */}
<Box sx={{ minHeight: '40px', mt: '5px', mb: '5px' }}>
<Typography variant="body1">{header}</Typography>
</Box>

{/* Selector if isSelectable */}
{isSelectable && (
<Box sx={{
mb: 2,
backgroundColor: theme.palette.primary.white,
borderRadius: 2,
p: 2
}}>
<DropDownSelector
availableSelections={availableSelections}
selections={cards}
setSelections={(newSelections) => onSelectionChange(header.toLowerCase(), newSelections)}
option={header}
/>
</Box>
)}

{/* Content */}
<Stack gap={2} useFlexGap={true}>
{cells}
</Stack>
</Box>
<Stack gap={2} useFlexGap={true}>
{ cells }
</Stack>
</Box>
)
}
}
Loading

0 comments on commit 8d463fb

Please sign in to comment.