Skip to content

Commit

Permalink
pull master
Browse files Browse the repository at this point in the history
  • Loading branch information
0101oak committed Sep 9, 2024
1 parent 08efdc7 commit fc655b6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
import { common_ProductNew } from 'api/proto-http/admin';
import { colors } from 'constants/colors';
import { isValid, parseISO } from 'date-fns';
import { generateOrUpdateSKU, generateSKU } from 'features/utilitty/dynamicGenerationOfSku';
import { findInDictionary } from 'features/utilitty/findInDictionary';
import { restrictNumericInput } from 'features/utilitty/removePossibilityToEnterSigns';
Expand All @@ -24,17 +23,8 @@ import CountryList from 'react-select-country-list';
import { v4 as uuidv4 } from 'uuid';
import { BasicProductFieldsInterface, Country } from '../interface/interface';
import { handleKeyDown } from '../utility/brandNameRegExp';

const parseWellKnownTimestamp = (timestamp: string): Date | null => {
if (!timestamp || timestamp === '0001-01-01T00:00:00Z') return null;
const parsedDate = parseISO(timestamp);
return isValid(parsedDate) ? parsedDate : null;
};

const formatWellKnownTimestamp = (date: Date | null): string => {
if (!date) return '0001-01-01T00:00:00Z';
return date.toISOString();
};
import { genderOptions } from '../utility/genderList';
import { formatWellKnownTimestamp, parseWellKnownTimestamp } from '../utility/preorderTime';

export const BasicFields: FC<BasicProductFieldsInterface> = ({
dictionary,
Expand All @@ -43,8 +33,7 @@ export const BasicFields: FC<BasicProductFieldsInterface> = ({
isAddingProduct,
isCopyMode,
}) => {
const { values, setFieldValue, submitCount, errors, touched } =
useFormikContext<common_ProductNew>();
const { values, setFieldValue, errors, touched } = useFormikContext<common_ProductNew>();
const countries = useMemo(() => CountryList().getData() as Country[], []);
const [showPreorder, setShowPreorder] = useState(true);
const [showSales, setShowSales] = useState(true);
Expand Down Expand Up @@ -133,9 +122,6 @@ export const BasicFields: FC<BasicProductFieldsInterface> = ({
return parseWellKnownTimestamp(dateString || '0001-01-01T00:00:00Z');
};

console.log(dictionary?.categories?.length); // Should log 20
console.log(dictionary?.categories); // Inspect if any category is missing

useEffect(() => {
const { salePercentage, preorder } = values.product?.productBody || {};
const saleValue = salePercentage?.value || '';
Expand Down Expand Up @@ -239,9 +225,9 @@ export const BasicFields: FC<BasicProductFieldsInterface> = ({
name='product.productBody.targetGender'
disabled={disableFields}
>
{dictionary?.genders?.map((gender) => (
{genderOptions.map((gender) => (
<MenuItem key={gender.id} value={gender.id}>
{gender.name?.replace('GENDER_ENUM_', '').toUpperCase()}
{gender.name?.toUpperCase()}
</MenuItem>
))}
</Select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const GenericProductForm: FC<GenericProductFormInterface> = ({
}) => {
const [isFormChanged, setIsFormChanged] = useState(false);
const [clearMediaPreview, setClearMediaPreview] = useState(false);
const navigate = useNavigate();
const initialValues = useMemo(() => initialProductState, [initialProductState]);
const navigate = useNavigate();

useEffect(() => {
const handleKeydown = (event: KeyboardEvent) => {
Expand Down Expand Up @@ -58,6 +58,8 @@ export const GenericProductForm: FC<GenericProductFormInterface> = ({
if (isAddingProduct && !isCopyMode) {
setClearMediaPreview(true);
setTimeout(() => setClearMediaPreview(false), 0);
} else if (isCopyMode) {
navigate({ to: ROUTES.product, replace: true });
}
};

Expand Down Expand Up @@ -88,13 +90,15 @@ export const GenericProductForm: FC<GenericProductFormInterface> = ({
sx={{ top: 'auto', bottom: 0, backgroundColor: 'transparent', boxShadow: 'none' }}
>
<Toolbar sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Button
onClick={() => handleCopyProductClick(product?.product?.id)}
size='small'
variant='contained'
>
copy
</Button>
{!isAddingProduct && (
<Button
onClick={() => handleCopyProductClick(product?.product?.id)}
size='small'
variant='contained'
>
copy
</Button>
)}
<Button
size='small'
variant='contained'
Expand All @@ -107,6 +111,7 @@ export const GenericProductForm: FC<GenericProductFormInterface> = ({
}
}}
disabled={isEditMode && !isFormChanged}
style={{ position: 'absolute', right: '30px' }}
>
{isSubmitting ? (
<CircularProgress size={24} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { common_Genders } from "api/proto-http/admin";

export const genderOptions: common_Genders[] = [
{ id: 'GENDER_ENUM_MALE', name: 'Male' },
{ id: 'GENDER_ENUM_FEMALE', name: 'Female' },
{ id: 'GENDER_ENUM_UNISEX', name: 'Unisex' },
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { isValid, parseISO } from 'date-fns';


export const parseWellKnownTimestamp = (timestamp: string): Date | null => {
if (!timestamp || timestamp === '0001-01-01T00:00:00Z') return null;
const parsedDate = parseISO(timestamp);
return isValid(parsedDate) ? parsedDate : null;
};

export const formatWellKnownTimestamp = (date: Date | null): string => {
if (!date) return '0001-01-01T00:00:00Z';
return date.toISOString();
};
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ export const Filter: FC<FilterProps> = ({ filter, onFilterChange }) => {
multiple
>
<MenuItem value=''>ANY</MenuItem>
{dictionary?.categories?.map((s) => (
<MenuItem key={s.id} value={s.id}>
{findInDictionary(dictionary, s.id, 'category')}
{dictionary?.categories?.map((category) => (
<MenuItem key={category.id} value={category.id}>
{findInDictionary(dictionary, category.id, 'category')}
</MenuItem>
))}
</Select>
Expand Down
3 changes: 1 addition & 2 deletions src/components/managers/products/products.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Grid, Theme, useMediaQuery } from '@mui/material';
import { Button, Grid } from '@mui/material';
import { useNavigate } from '@tanstack/react-location';
import { Layout } from 'components/login/layout';
import { ROUTES } from 'constants/routes';
Expand All @@ -7,7 +7,6 @@ import { AllProducts } from './listProducts/allProducts';

export const Product: FC = () => {
const navigate = useNavigate();
const isMobile = useMediaQuery((theme: Theme) => theme.breakpoints.down('sm'));

const navigateAddProduct = () => {
navigate({ to: ROUTES.addProduct });
Expand Down

0 comments on commit fc655b6

Please sign in to comment.