Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 85 additions & 1 deletion frontend/src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
PopupDialog,
PopupEditAvatar,
PopupAskToRegister,
PopupShareCalendar,
} from '../Popups';

const locales = {
Expand Down Expand Up @@ -83,6 +84,7 @@ function App() {
const [chosenCalendars, setChosenCalendars] = useState([]);
const [editableCalendar, setEditableCalendar] = useState({});
const [editableEvent, setEditableEvent] = useState({});
const [team, setTeam] = useState([]);

// Popups
const [visiblePopupLogin, setVisiblePopupLogin] = useState(false);
Expand All @@ -97,6 +99,8 @@ function App() {
useState(false);
const [visiblePopupAskToRegister, setVisiblePopupAskToRegister] =
useState(false);
const [visiblePopupShareCalendar, setVisiblePopupShareCalendar] =
useState(false);

// Helpers
const [showMessage, setShowMessage] = useState(false);
Expand Down Expand Up @@ -147,6 +151,7 @@ function App() {
setCurrentUser({});
setAllUserCalendars([]);
setAllUserEvents([]);
setTeam([]);
setChosenCalendars(holidaysCalendar.map((c) => c.id));
closeAllPopups();

Expand All @@ -157,7 +162,9 @@ function App() {

const handleErrors = useCallback(
({ error, res }) => {
if (error.code === 'token_not_valid') {
console.log({ error, res });

if (error.code && error.code === 'token_not_valid') {
logout();
showDialog(ErrorMessage.UNAUTHORIZED, true);
} else if (res.status === 401) {
Expand Down Expand Up @@ -302,6 +309,7 @@ function App() {
setEditableCalendar,
editableEvent,
setEditableEvent,
team,
}),
[
holidays,
Expand All @@ -310,6 +318,7 @@ function App() {
chosenCalendars,
editableCalendar,
editableEvent,
team,
]
);

Expand Down Expand Up @@ -660,6 +669,73 @@ function App() {
});
};

const handleShareCalendar = (data) => {
const newMate = {
email: data.email,
infoIcon: 'load',
};
setTeam([...team, newMate]);

calendarApi
.shareCalendar(data)
.then(() => {
newMate.infoIcon = 'success';

const index = team.findIndex((m) => m.email === data.email);
if (index !== -1) {
team.splice(index, 1);
}

setTeam([...team, newMate]);
})
.catch((/* { error, res } */) => {
newMate.infoIcon = 'denied';

const index = team.findIndex((m) => m.email === data.email);
if (index !== -1) {
team.splice(index, 1);
}

setTeam([...team, newMate]);
// handleErrors({ error, res });
});
};

const handleDeleteMate = ({ id, email }) => {
setIsLoading(true);
calendarApi
.deleteSharedCalendar({ id, email })
.then(() => {
const index = team.findIndex((m) => m.email === email);
if (index !== -1) {
team.splice(index, 1);
}
})
.catch(({ err, res }) => {
handleErrors({ err, res });
})
.finally(() => {
setIsLoading(false);
});
};

const handleShowSharePopup = (id) => {
setIsLoading(true);
calendarApi
.getSharedCalendarById(id)
.then((res) => {
setTeam(res.users);
setVisiblePopupShareCalendar(true);
})
.catch(({ error, res }) => {
console.log({ error, res });
handleErrors({ error, res });
})
.finally(() => {
setIsLoading(false);
});
};

return (
<LocalizationContext.Provider value={localizer}>
<CurrentUserContext.Provider value={user}>
Expand All @@ -683,6 +759,7 @@ function App() {
onEventDoubleClick={setVisiblePopupEditEvent}
onNewCalendarClick={setVisiblePopupNewCalendar}
onEditCalendarClick={setVisiblePopupEditCalendar}
onShareCalendarClick={handleShowSharePopup}
onNewEventClickUnauth={setVisiblePopupAskToRegister}
onEditEvent={handleEditEvent}
/>
Expand Down Expand Up @@ -757,6 +834,13 @@ function App() {
setIsFormLogin={setIsFormLogin}
/>

<PopupShareCalendar
visible={visiblePopupShareCalendar}
setVisible={setVisiblePopupShareCalendar}
handleShare={handleShareCalendar}
handleDeleteMate={handleDeleteMate}
/>

<Toast ref={toast} />

<PopupDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
width: 60px;
font-size: 60px;
border: none;
transition: transform 0.25s linear;
transition: transform 0.1s linear;
cursor: pointer;
}

Expand All @@ -21,7 +21,8 @@
top: 92vh;
right: 0px;
height: 50px;
width: 60px;
width: 56px;
visibility: hidden;
}

.button:hover {
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/components/CalendarSelect/CalendarSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styles from './CalendarSelect.module.css';
/* Components */
import { CalendarBlock } from './CalendarsBlock';

export function CalendarSelect({ onEditCalendarClick }) {
export function CalendarSelect({ onEditCalendarClick, onShareCalendarClick }) {
const { allUserCalendars, setChosenCalendars, setEditableCalendar } =
useContext(CalendarsContext);

Expand All @@ -27,9 +27,13 @@ export function CalendarSelect({ onEditCalendarClick }) {
}
};

const handleClick = (calendar) => {
const handleClick = (calendar, isEdit) => {
setEditableCalendar(calendar);
onEditCalendarClick(true);
if (isEdit) {
onEditCalendarClick(true);
} else {
onShareCalendarClick(calendar.id);
}
};

// TODO: потом сюда добявятся пошаренные календари
Expand Down Expand Up @@ -57,4 +61,5 @@ export function CalendarSelect({ onEditCalendarClick }) {

CalendarSelect.propTypes = {
onEditCalendarClick: PropTypes.func.isRequired,
onShareCalendarClick: PropTypes.func.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

.list {
display: grid;
grid-template-columns: 16px 1fr 16px;
grid-template-columns: 16px 1fr 44px;
grid-column-gap: 8px;
align-items: start;
cursor: pointer;
Expand Down Expand Up @@ -107,8 +107,14 @@ label input:checked ~ .checkbox::before {
cursor: pointer;
padding: 0;
transition: all 0.2s ease-out;
width: 16px;
height: 16px;
}

.edit:hover {
color: var(--surface-200);
}

.edit:first-child {
margin-right: 12px;
}
31 changes: 24 additions & 7 deletions frontend/src/components/CalendarSelect/CalendarsBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,30 @@ export function CalendarBlock(props) {
/>
<span className={styles.text}>{calendar.name}</span>
{editButton && (
<button
className={styles.edit}
type="button"
onClick={() => handleClick(calendar)}
>
<i className="pi pi-pencil" style={{ fontSize: '0.75rem' }} />
</button>
<div className="flex">
<button
className={styles.edit}
type="button"
onClick={() => handleClick(calendar, true)}
>
<i
className="pi pi-pencil"
style={{ fontSize: '0.75rem' }}
/>
</button>
<button
className={styles.edit}
type="button"
onClick={() => handleClick(calendar, false)}
>
<i
className={
calendar.shared ? 'pi pi-users' : 'pi pi-share-alt'
}
style={{ fontSize: '0.75rem' }}
/>
</button>
</div>
)}
</label>
))}
Expand Down
Loading