mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-13 08:13:49 +10:00
188 lines
5.0 KiB
JavaScript
188 lines
5.0 KiB
JavaScript
import React, { useState, useContext } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
import set from 'lodash/set';
|
|
|
|
import TextField from '../../../shared/TextField';
|
|
import TextArea from '../../../shared/TextArea';
|
|
import AppContext from '../../../context/AppContext';
|
|
import Checkbox from '../../../shared/Checkbox';
|
|
import { addItem } from '../../../utils';
|
|
import ItemActions from '../../../shared/ItemActions';
|
|
import AddItemButton from '../../../shared/AddItemButton';
|
|
|
|
const WorkTab = ({ data, onChange }) => {
|
|
const { t } = useTranslation('app');
|
|
const context = useContext(AppContext);
|
|
const { dispatch } = context;
|
|
|
|
return (
|
|
<>
|
|
<div className="mb-6 grid grid-cols-6 items-center">
|
|
<div className="col-span-1">
|
|
<Checkbox checked={data.work.enable} onChange={v => onChange('data.work.enable', v)} />
|
|
</div>
|
|
<div className="col-span-5">
|
|
<TextField
|
|
placeholder={t('heading.placeholder')}
|
|
value={data.work.heading}
|
|
onChange={v => onChange('data.work.heading', v)}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<hr className="my-6" />
|
|
|
|
{data.work.items.map((x, index) => (
|
|
<Item
|
|
dispatch={dispatch}
|
|
first={index === 0}
|
|
index={index}
|
|
item={x}
|
|
key={x.id}
|
|
last={index === data.work.items.length - 1}
|
|
onChange={onChange}
|
|
/>
|
|
))}
|
|
|
|
<AddItem heading={data.work.heading} dispatch={dispatch} />
|
|
</>
|
|
);
|
|
};
|
|
|
|
const Form = ({ item, onChange, identifier = '' }) => {
|
|
const { t } = useTranslation(['leftSidebar', 'app']);
|
|
|
|
return (
|
|
<div>
|
|
<TextField
|
|
className="mb-6"
|
|
label={t('work.name.label')}
|
|
placeholder={t('work.name.placeholder')}
|
|
value={item.title}
|
|
onChange={v => onChange(`${identifier}title`, v)}
|
|
/>
|
|
|
|
<TextField
|
|
className="mb-6"
|
|
label={t('work.role.label')}
|
|
placeholder={t('work.role.placeholder')}
|
|
value={item.role}
|
|
onChange={v => onChange(`${identifier}role`, v)}
|
|
/>
|
|
|
|
<div className="grid grid-cols-2 col-gap-4">
|
|
<TextField
|
|
className="mb-6"
|
|
label={t('app:item.startDate.label')}
|
|
placeholder={t('app:item.startDate.placeholder')}
|
|
value={item.start}
|
|
onChange={v => onChange(`${identifier}start`, v)}
|
|
/>
|
|
|
|
<TextField
|
|
className="mb-6"
|
|
label={t('app:item.endDate.label')}
|
|
placeholder={t('app:item.endDate.placeholder')}
|
|
value={item.end}
|
|
onChange={v => onChange(`${identifier}end`, v)}
|
|
/>
|
|
</div>
|
|
|
|
<TextArea
|
|
rows="5"
|
|
className="mb-6"
|
|
label={t('app:item.description.label')}
|
|
placeholder={t('work.description.placeholder')}
|
|
value={item.description}
|
|
onChange={v => onChange(`${identifier}description`, v)}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const AddItem = ({ heading, dispatch }) => {
|
|
const { t } = useTranslation('app');
|
|
|
|
const [isOpen, setOpen] = useState(false);
|
|
const [item, setItem] = useState({
|
|
id: uuidv4(),
|
|
enable: true,
|
|
title: '',
|
|
role: '',
|
|
start: '',
|
|
end: '',
|
|
description: '',
|
|
});
|
|
|
|
const onChange = (key, value) => setItem(set({ ...item }, key, value));
|
|
|
|
const onSubmit = () => {
|
|
if (item.title === '' || item.role === '') return;
|
|
|
|
addItem(dispatch, 'work', item);
|
|
|
|
setItem({
|
|
id: uuidv4(),
|
|
enable: true,
|
|
title: '',
|
|
role: '',
|
|
start: '',
|
|
end: '',
|
|
description: '',
|
|
});
|
|
|
|
setOpen(false);
|
|
};
|
|
|
|
return (
|
|
<div className="my-4 border border-gray-200 rounded p-5">
|
|
<div
|
|
className="flex justify-between items-center cursor-pointer"
|
|
onClick={() => setOpen(!isOpen)}
|
|
>
|
|
<h6 className="text-sm font-medium">{t('item.addHeading', { heading })}</h6>
|
|
<i className="material-icons">{isOpen ? 'expand_less' : 'expand_more'}</i>
|
|
</div>
|
|
|
|
<div className={`mt-6 ${isOpen ? 'block' : 'hidden'}`}>
|
|
<Form item={item} onChange={onChange} />
|
|
<AddItemButton onSubmit={onSubmit} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const Item = ({ item, index, onChange, dispatch, first, last }) => {
|
|
const [isOpen, setOpen] = useState(false);
|
|
const identifier = `data.work.items[${index}].`;
|
|
|
|
return (
|
|
<div className="my-4 border border-gray-200 rounded p-5">
|
|
<div
|
|
className="flex justify-between items-center cursor-pointer"
|
|
onClick={() => setOpen(!isOpen)}
|
|
>
|
|
<h6 className="ml-2 text-sm font-medium">{item.title}</h6>
|
|
<i className="material-icons">{isOpen ? 'expand_less' : 'expand_more'}</i>
|
|
</div>
|
|
|
|
<div className={`mt-6 ${isOpen ? 'block' : 'hidden'}`}>
|
|
<Form item={item} onChange={onChange} identifier={identifier} />
|
|
|
|
<ItemActions
|
|
dispatch={dispatch}
|
|
first={first}
|
|
identifier={identifier}
|
|
item={item}
|
|
last={last}
|
|
onChange={onChange}
|
|
type="work"
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default WorkTab;
|