Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/embed calendar in reservation #259

Merged
merged 26 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2d70511
added calendar feature
melikaamm Sep 24, 2024
35482a9
Solved merge conflict
miklesch Oct 12, 2024
b809dbd
Resolved merge conflicts
miklesch Oct 18, 2024
ce110a4
Changed to module.css
miklesch Oct 18, 2024
81903a8
Placed Calendar to searchbar
miklesch Oct 18, 2024
99ca754
Merge branch 'main' into feature/calender
miklesch Oct 21, 2024
b7df227
Using ModalPopUp for Calendar component
miklesch Oct 21, 2024
87eea15
Changed some styling
miklesch Oct 22, 2024
8e8ebce
Merge branch 'main' into feature/calender
miklesch Oct 22, 2024
1e10cb9
Merge branch 'main' into feature/calender
miklesch Oct 28, 2024
3306db6
Merge remote-tracking branch 'origin/main' into feature/calender
grabinskij Oct 28, 2024
aa61906
Apply styles to the className instead of general styling for button t…
grabinskij Oct 28, 2024
47c37e8
Create Calendar handler
grabinskij Oct 30, 2024
3a3427b
Use special styles for the dates before the current date.
grabinskij Oct 30, 2024
ef5ba78
Replace inputs with divs to display state values like in original AirBnB
grabinskij Oct 30, 2024
9e9c50b
Implement flipping animation while changing months
grabinskij Oct 31, 2024
a5ee84e
Move DataIncrementsButtonForTheCalendar to the calendarWrapper
grabinskij Oct 31, 2024
bfce4dd
Make Calender component reusable by adding apportunity to change widt…
grabinskij Oct 31, 2024
3992ed9
Implement useOutsideClick hook to close the dropdown by clicking outs…
grabinskij Oct 31, 2024
28c62f1
Fix bug to allow useOutsideClick hook work properly with setShowCalendar
grabinskij Oct 31, 2024
c8ef6d3
Create function to close Calendar on the SearchBar by hover with anim…
grabinskij Oct 31, 2024
fd5a401
Add textDecoration props to have opportunity reuse component in diffe…
grabinskij Oct 31, 2024
5b0e184
Build in Calendar into ReservationDatesSelector
grabinskij Nov 1, 2024
f3c5205
Merge branch 'main' into feature/embedCalendarInReservation
grabinskij Nov 1, 2024
37a0ab2
Comment the test that is not related to the project
grabinskij Nov 1, 2024
1ded60f
Merge branch 'main' into feature/embedCalendarInReservation
006080 Nov 1, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ Currently, two official plugins are available:
- Bhagya Samarathunga ( [@BhagyaPrasadSamarathunga] (https://github.com/BhagyaPrasadSamarathunga))
- Gabriel Melhem ([@GabrielMelhem] (https://github.com/GabrielMelhem))
- Iman Bajalan ([@BajalanIman](https://github.com/BajalanIman))
- Nataliya Rodionova ([@006080](https://github.com/006080))
- Nataliya Rodionova ([@006080](https://github.com/006080))
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import axios from "axios";
import { BASE_URL } from "./constants/constants";
import DataIncrementsButtonForTheCalendar from "./components/DataIncrementsButtonForTheCalendar/DataIncrementsButtonForTheCalendar";
import CategoryTabs from "./components/CategoryTabs/CategoryTabs";

function App() {
const [places, setPlaces] = useState([]);
const [selectPlaceId, setSelectPlaceId] = useState(null);
Expand Down Expand Up @@ -40,6 +41,7 @@ function App() {

<DataIncrementsButtonForTheCalendar />
<CategoryTabs />

<div className="grid">
{places.map((place) => {
if (!place.id) return null;
Expand Down
3 changes: 2 additions & 1 deletion src/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { render, screen } from '@testing-library/react'
import { test, expect } from 'vitest';
import App from './App'


/*
test('loads and displays greeting', async () => {
// Render a React element into the DOM
render(<App />)
Expand All @@ -15,3 +15,4 @@ test('loads and displays greeting', async () => {
// assert that they work correctly
expect(heading.innerHTML).toEqual('Hello F24-Berlin-Web-Circle')
})
*/
Binary file not shown.
134 changes: 134 additions & 0 deletions src/components/Calendar/Calendar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import React, { useState } from 'react'
import styles from './Calendar.module.css'
import { CalendarLeftArrowIcon, CalendarRightArrowIcon } from '../../icons'

const Calendar = ({
dayItemWidth,
dayItemHeight,
textDecoration,
monthContainerPadding,
buttonRightMargin,
buttonLeftMargin
}) => {
const [currentMonth, setCurrentMonth] = useState(new Date())
const [animationDirection, setAnimationDirection] = useState("")

const getDaysInMonth = (year, month) => new Date(year, month + 1, 0).getDate()
const getFirstDayOfMonth = (year, month) => new Date(year, month, 1).getDay()

const goToNextMonth = () => {
setAnimationDirection("flip-right")
setCurrentMonth(
new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1)
)
resetAnimation()
}
const goToPrevMonth = () => {
setAnimationDirection("flip-left")
setCurrentMonth(
new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1)
)
resetAnimation()
}

const resetAnimation = () => {
setTimeout(() => setAnimationDirection(""), 300)
}

const renderDaysOfWeek = () => {
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
return days.map((day, index) => (
<div key={index} className={styles.dayHeader}>
{day}
</div>
))
}

const renderDays = (year, month, isCurrentMonth) => {
const today = new Date().setHours(0, 0, 0, 0)
const daysInMonth = getDaysInMonth(year, month)
const firstDayOfMonth = getFirstDayOfMonth(year, month)
const daysArray = []

for (let i = 0; i < firstDayOfMonth; i++) {
daysArray.push(
<div key={`empty-${i}`} className={styles.emptySlot}></div>
)
}

for (let day = 1; day <= daysInMonth; day++) {
const date = new Date(year, month, day).setHours(0, 0, 0, 0)
const isPastDate = isCurrentMonth && date < today

daysArray.push(
<div
key={day}
className={`${styles.date} ${isPastDate ? styles.pastDate : ''}`}
style={{
"--pastDate-line-through": textDecoration,
}}
>
{day}
</div>
)
}
return daysArray
}

const renderCalendarForMonth = (date) => {
const year = date.getFullYear()
const month = date.getMonth()
const monthName = date.toLocaleString('default', { month: 'long' })
const isCurrentMonth =
currentMonth.getFullYear() === year && currentMonth.getMonth() === month

return (
<div className={`${styles.monthContainer} ${styles[animationDirection]}`}
style={{
"--day-item-width": dayItemWidth,
"--day-item-height": dayItemHeight,
"--month-container-padding": monthContainerPadding
}}
>
<h3>{`${monthName} ${year}`}</h3>
<div className={styles.calendarGrid}>
{renderDaysOfWeek()}
{renderDays(year, month, isCurrentMonth)}
</div>
</div>
)
}

const getNextMonth = () =>
new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1)

return (
<div className={styles.calendarPopUp}>
<div className={styles.calendar}>
<div className={styles.calendarRow}>
<button
className={styles.prevButton}
style={{"--button-right-margin": buttonRightMargin}}
onClick={goToPrevMonth}
disabled={currentMonth <= new Date()}
>
<CalendarLeftArrowIcon />
</button>

{renderCalendarForMonth(currentMonth)}
{renderCalendarForMonth(getNextMonth())}

<button
className={styles.nextButton}
style={{"--button-left-margin": buttonLeftMargin}}
onClick={goToNextMonth}
>
<CalendarRightArrowIcon />
</button>
</div>
</div>
</div>
)
}

export default Calendar
106 changes: 106 additions & 0 deletions src/components/Calendar/Calendar.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
.calendar {
display: flex;
flex-direction: column;
justify-content: center;
color: var(--primary);
}

.calendarRow {
display: flex;
justify-content: center;
align-items: flex-start;
width: 100%;
}

.monthContainer {
max-width: 390px;
padding: 0 var(--month-container-padding, 27px);
}

.calendarGrid {
display: grid;
grid-template-columns: repeat(7, 1fr);
}

.dayHeader,
.date,
.emptySlot {
display: flex;
align-items: center;
justify-content: center;
width: var(--day-item-width, 40px);
height: var(--day-item-height, 40px);
font-size: 14px;
font-weight: 500;
}
.monthContainer h3 {
font-size: 16px;
margin-bottom: 10px;
text-align: center;
}

.date.pastDate {
color: #484848;
opacity: 0.3;
text-decoration: var(--pastDate-line-through, none);
}

.prevButton,
.nextButton {
font-size: 16px;
background: none;
border: none;
cursor: pointer;
outline: none;
z-index: 5;
border-radius: 50%;
padding: 0;
margin-top: 10px;
}

.prevButton:hover,
.nextButton:hover {
background-color: #f7f7f7;
}

.prevButton {
margin-right: var(--button-right-margin, -60px);
}
.nextButton {
margin-left: var(--button-left-margin, -60px);
}
.prevButton:disabled {
background-color: white;
cursor: not-allowed;
opacity: 0.6;
}

@keyframes flipRightToLeft {
0% {
transform: translateX(16%);
opacity: 0;
}
100% {
transform: translateX(0);
opacity: 1;
}
}

@keyframes flipLeftToRight {
0% {
transform: translateX(-16%);
opacity: 0;
}
100% {
transform: translateX(0);
opacity: 1;
}
}

.monthContainer.flip-right {
animation: flipRightToLeft 0.4s ease forwards;
}

.monthContainer.flip-left {
animation: flipLeftToRight 0.4s ease forwards;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.dateSelectionContainer {
margin-top: 40px;
display: flex;
gap: 10px;
justify-content: center;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Footer/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ const Footer = () => {
);
};

export default Footer;
export default Footer;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
justify-content: center;
box-sizing: border-box;
}

.leafSide {
width: 68%;
height: 100%;
Expand All @@ -27,21 +26,18 @@
justify-content: center;
align-items: center;
}

.roundPhotoComponent {
display: flex;
justify-content: center;
align-items: center;
position: relative;
}

.personImg {
width: 100px;
height: 100px;
border-radius: 100%;
opacity: 0.9;
}

.verifiedContainer {
display: flex;
justify-content: center;
Expand All @@ -52,30 +48,35 @@
position: absolute;
margin-left: 70px;
}

.verifiediconSvg {
width: 20px;
height: 20px;
fill: white;
}
.personRoleContainer {
display: flex;
margin-top: 10px;
gap: 0px;
flex-direction: column;
align-items: center;
}

.personInfo {
font-size: 30px;
font-weight: 700;
line-height: 0%;
}

.roleContainer {
margin-top: -10px;
}
.roleiconSvg {
width: 12px;
height: 12px;
}

.role {
font-size: 13px;
font-weight: bold;
}

.rightSide {
width: 32%;
display: flex;
Expand All @@ -85,14 +86,14 @@
flex-direction: column;
justify-content: center;
}

.reviewsContainer {
display: flex;
flex-direction: column;
align-items: start;
width: 100%;
}


.reviewsAndStar {
display: flex;
}
Expand All @@ -106,7 +107,6 @@
font-size: 11px;
font-weight: 500;
}

.starSvg {
width: 14px;
height: 14px;
Expand All @@ -131,10 +131,6 @@
text-decoration: underline;
}

.personTextContainer {
/* margin-bottom: 12px; */
}

.personText{
display: flex;
gap: 32px;
Expand Down
Loading