Skip to content

Commit 0d638b5

Browse files
Merge pull request #174 from 0101oak/feature/care-styles
care styles + dropdown for filter on product page
2 parents 3b2fb06 + 45c055e commit 0d638b5

File tree

6 files changed

+349
-284
lines changed

6 files changed

+349
-284
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"react-text-truncate": "^0.19.0",
104104
"react-use-auth": "^2.1.0-14",
105105
"stream-browserify": "^3.0.0",
106+
"swiper": "^11.1.14",
106107
"uuid": "^11.0.3",
107108
"yup": "^1.4.0"
108109
}

src/components/managers/products/genericProductComponent/care/care.scss

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
flex-direction: column;
2020
align-items: center;
2121
justify-content: center;
22-
padding: 0.5rem;
2322

2423
.care-card-img-container {
24+
padding: 0.4rem;
2525
display: flex;
2626
justify-content: center;
2727
flex: 0 0 auto;
@@ -33,7 +33,7 @@
3333
align-items: center;
3434
justify-content: center;
3535
text-align: center;
36-
max-width: 100%;
36+
max-width: 90%;
3737
overflow-wrap: break-word;
3838

3939
.text {
@@ -46,11 +46,7 @@
4646

4747
&[data-selected='true'] {
4848
border-color: var(--mui-primary-main, #000);
49-
background-color: var(--mui-action-selected, rgba(0, 0, 0, 0.08));
50-
}
51-
52-
&:hover {
53-
background-color: rgba(0, 0, 0, 0.04);
49+
border-width: 4px;
5450
}
5551

5652
&:before {

src/components/managers/products/genericProductComponent/care/care.tsx

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Button, Grid, Typography } from '@mui/material';
1+
import { Button, Grid2 as Grid, TextField } from '@mui/material';
22
import { common_ProductNew } from 'api/proto-http/admin';
33
import { useFormikContext } from 'formik';
44
import { FC, useState } from 'react';
@@ -8,10 +8,22 @@ interface SelectedInstructions {
88
[category: string]: string;
99
}
1010

11-
export const Care: FC = () => {
11+
interface CareInterface {
12+
isAddingProduct: boolean;
13+
isEditMode?: boolean;
14+
}
15+
16+
export const Care: FC<CareInterface> = ({ isAddingProduct, isEditMode }) => {
1217
const [isCareTableOpen, setIsCareTableOpen] = useState(false);
1318
const { values, setFieldValue } = useFormikContext<common_ProductNew>();
14-
const [selectedInstructions, setSelectedInstructions] = useState<SelectedInstructions>({});
19+
const [selectedInstructions, setSelectedInstructions] = useState<SelectedInstructions>(() => {
20+
const careInstructions = values.product?.productBody?.careInstructions || '';
21+
const instructions = careInstructions.split(',').filter(Boolean);
22+
return instructions.reduce((acc, code) => {
23+
acc[code] = code;
24+
return acc;
25+
}, {} as SelectedInstructions);
26+
});
1527

1628
// ... existing code ...
1729
const handleSelectCareInstruction = (
@@ -52,15 +64,42 @@ export const Care: FC = () => {
5264
setIsCareTableOpen(false);
5365
};
5466

67+
const handleClearInstructions = () => {
68+
setSelectedInstructions({});
69+
setFieldValue('product.productBody.careInstructions', '');
70+
};
71+
5572
return (
56-
<Grid>
57-
<Button onClick={handleOpenCareTable}>Care Instructions</Button>
58-
{Object.keys(selectedInstructions).length > 0 && (
59-
<Grid item xs={12}>
60-
<Typography variant='subtitle2'>Selected Instructions:</Typography>
61-
<Typography variant='body2'>{Object.values(selectedInstructions).join(', ')}</Typography>
62-
</Grid>
63-
)}
73+
<Grid container>
74+
<Grid size={{ xs: 12 }}>
75+
<TextField
76+
fullWidth
77+
variant='outlined'
78+
name='product.productBody.careInstructions'
79+
label='Care Instructions'
80+
value={values.product?.productBody?.careInstructions || ''}
81+
slotProps={{
82+
input: {
83+
readOnly: true,
84+
endAdornment: (isAddingProduct || isEditMode) && (
85+
<>
86+
<Button
87+
variant='outlined'
88+
onClick={handleClearInstructions}
89+
sx={{ mr: 1 }}
90+
disabled={!values.product?.productBody?.careInstructions}
91+
>
92+
Clear
93+
</Button>
94+
<Button variant='contained' onClick={handleOpenCareTable}>
95+
Select
96+
</Button>
97+
</>
98+
),
99+
},
100+
}}
101+
/>
102+
</Grid>
64103
<CareInstructions
65104
isCareTableOpen={isCareTableOpen}
66105
close={handleCloseCareTable}

src/components/managers/products/genericProductComponent/care/careInstructions.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import CloseIcon from '@mui/icons-material/Close';
12
import {
23
Dialog,
34
FormControl,
45
FormControlLabel,
5-
Grid,
6+
Grid2 as Grid,
7+
IconButton,
68
Radio,
79
RadioGroup,
810
Typography,
@@ -36,7 +38,7 @@ export const CareInstructions: FC<CareInstructionsProps> = ({
3638
selectedInstructions,
3739
}) => {
3840
const careCategories = Object.keys(careInstruction.care_instructions);
39-
const [selectedCare, setSelectedCare] = useState<string | null>(null);
41+
const [selectedCare, setSelectedCare] = useState<string | null>('Washing');
4042
const theme = useTheme();
4143
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
4244

@@ -53,7 +55,7 @@ export const CareInstructions: FC<CareInstructionsProps> = ({
5355
const isSelected = selectedInstructions[selectionKey] === code;
5456

5557
return (
56-
<Grid item xs={4} sm={1.5} key={code}>
58+
<Grid size={{ xs: 4, sm: 1.5 }} key={code}>
5759
<Grid
5860
container
5961
onClick={() => onSelectCareInstruction(selectedCare!, method, code, subCategory)}
@@ -62,14 +64,14 @@ export const CareInstructions: FC<CareInstructionsProps> = ({
6264
>
6365
<Grid container className={styles['care-card']}>
6466
{img && (
65-
<Grid item className={styles['care-card-img-container']}>
67+
<Grid className={styles['care-card-img-container']}>
6668
<img src={img} alt={method} style={{ width: isMobile ? '25px' : '50px' }} />
6769
</Grid>
6870
)}
69-
<Grid item className={styles['care-card-text']}>
71+
<Grid className={styles['care-card-text']}>
7072
<Typography
7173
variant='overline'
72-
fontSize={isMobile ? '0.3rem' : '0.5rem'}
74+
fontSize={isMobile ? '0.4em' : '0.5em'}
7375
className={styles.text}
7476
>
7577
{method}
@@ -81,9 +83,9 @@ export const CareInstructions: FC<CareInstructionsProps> = ({
8183
);
8284
} else {
8385
return (
84-
<Grid item xs={12} key={method}>
86+
<Grid size={{ xs: 12 }} key={method}>
8587
<Typography variant='subtitle1' fontWeight='bold' sx={{ mb: 1 }}>
86-
{method}
88+
{method.toUpperCase()}
8789
</Typography>
8890
<Grid container spacing={2}>
8991
{renderCareMethods(codeOrSubMethods, method)}
@@ -108,11 +110,15 @@ export const CareInstructions: FC<CareInstructionsProps> = ({
108110
m: isMobile ? 0 : 2,
109111
height: isMobile ? '100%' : 'auto',
110112
maxHeight: isMobile ? '100%' : '90vh',
113+
position: 'relative',
111114
},
112115
}}
113116
>
117+
<IconButton onClick={close} sx={{ position: 'absolute', top: 0, right: 0, zIndex: 1 }}>
118+
<CloseIcon />
119+
</IconButton>
114120
<Grid container spacing={2} sx={{ p: 2 }}>
115-
<Grid item xs={12} sx={{ display: 'flex', justifyContent: 'center' }}>
121+
<Grid size={{ xs: 12 }} sx={{ display: 'flex', justifyContent: 'center' }}>
116122
<FormControl>
117123
<RadioGroup
118124
row
@@ -132,7 +138,7 @@ export const CareInstructions: FC<CareInstructionsProps> = ({
132138
</FormControl>
133139
</Grid>
134140
{selectedCare && (
135-
<Grid item xs={12}>
141+
<Grid size={{ xs: 12 }}>
136142
<Grid container spacing={2}>
137143
{renderCareMethods(
138144
careInstruction.care_instructions[

0 commit comments

Comments
 (0)