Skip to content

Commit

Permalink
- Configured Tailwind CSS for the Next.js app styling
Browse files Browse the repository at this point in the history
- Created and imported global CSS with Tailwind directives
- Added and (basic) styled HomePage, Greeting, and Button components with Tailwind CSS, to test
- Added _app.tsx to import global styles
- Implemented basic user profile management features (WIP - needs further developing)
- Created API endpoints for fetching and updating user profiles.
- Implemented the search function (needs UI)
- Set up email notifications using Nodemailer (needs UI)
  • Loading branch information
OzPol authored Jul 1, 2024
1 parent 3b43dbc commit 96e3c70
Show file tree
Hide file tree
Showing 22 changed files with 1,476 additions and 37 deletions.
42 changes: 42 additions & 0 deletions components/AvailabilityCalendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// components/AvailabilityCalendar.tsx

import React, { useState } from 'react';
import Calendar, { CalendarProps } from 'react-calendar';
import 'react-calendar/dist/Calendar.css';

// Define a DateRange type
type DateRange = [Date, Date];

const AvailabilityCalendar: React.FC = () => {
const [date, setDate] = useState<Date | DateRange>(new Date());

const onChange: CalendarProps['onChange'] = (newDate) => {
if (newDate instanceof Date) {
setDate(newDate);
} else if (
Array.isArray(newDate) &&
newDate.every((value) => value instanceof Date)
) {
setDate(newDate as DateRange);
} else {
setDate(new Date());
}
// TODO: Handle date selection (e.g., fetch availability or bookings)
console.log('Selected date:', date);
// TODO: Add code here to fetch availability or bookings based on the selected date
};

return (
<div>
<Calendar onChange={onChange} value={date} />
<p>
Selected date:{' '}
{Array.isArray(date)
? date.map((d) => d.toDateString()).join(', ')
: date.toDateString()}
</p>
</div>
);
};

export default AvailabilityCalendar;
22 changes: 22 additions & 0 deletions components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// components/Button.tsx
// components/Button.tsx
import React, { useState } from 'react';

const Button: React.FC = () => {
const [clicked, setClicked] = useState(false);

const handleClick = () => {
setClicked(true);
};

return (
<button
style={{ backgroundColor: 'blue', color: 'white' }}
onClick={handleClick}
>
{clicked ? 'Clicked!' : 'Click Me'}
</button>
);
};

export default Button;
9 changes: 9 additions & 0 deletions components/FormattedDate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// components/FormattedDate.tsx
import React from 'react';
import { formatDate } from '../utils/formatDate';

const FormattedDate: React.FC<{ date: Date }> = ({ date }) => {
return <span>{formatDate(date)}</span>;
};

export default FormattedDate;
43 changes: 43 additions & 0 deletions components/Greeting.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// components/Greeting.tsx
// a simple React component that displays a greeting
// components/Greeting.tsx
import React, { useState } from 'react';

interface GreetingProps {
name: string;
}

const Greeting: React.FC<GreetingProps> = ({ name }) => {
const [greetingName, setGreetingName] = useState(name);
const [inputValue, setInputValue] = useState('');

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputValue(e.target.value);
};

const handleClick = () => {
setGreetingName(inputValue);
setInputValue('');
};

return (
<div className="p-4 bg-white shadow-md rounded-md mb-4">
<h1 className="text-2xl font-bold mb-4">Hello, {greetingName}!</h1>
<input
type="text"
value={inputValue}
onChange={handleChange}
placeholder="Enter your name"
className="border p-2 mb-4 w-full"
/>
<button
onClick={handleClick}
className="bg-blue-500 text-white py-2 px-4 rounded w-full"
>
Change Name
</button>
</div>
);
};

export default Greeting;
61 changes: 61 additions & 0 deletions components/ProfileDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// components/ProfileDetails.tsx
// Create a profile page to display and update user information.
// This page will show the user's profile and allow updates.

import React, { useState, useEffect } from 'react';
import axios from 'axios';

const ProfileDetails: React.FC = () => {
const [profile, setProfile] = useState<{
name: string;
email: string;
} | null>(null);
const [loading, setLoading] = useState(true);

useEffect(() => {
const fetchProfile = async () => {
try {
const { data } = await axios.get('/api/profile/1'); // Example user ID
setProfile(data);
} catch (error) {
console.error('Error fetching profile:', error);
} finally {
setLoading(false);
}
};

fetchProfile();
}, []);

if (loading) {
return <p>Loading...</p>;
}

return (
<div>
<h1>User Profile</h1>
{profile && (
<div>
<p>Name: {profile.name}</p>
<p>Email: {profile.email}</p>
<form
onSubmit={async (e) => {
e.preventDefault();
try {
const updatedProfile = { ...profile, name: 'New Name' }; // Example update
await axios.post('/api/profile/update', updatedProfile);
setProfile(updatedProfile);
} catch (error) {
console.error('Error updating profile:', error);
}
}}
>
<button type="submit">Update Profile</button>
</form>
</div>
)}
</div>
);
};

export default ProfileDetails;
30 changes: 30 additions & 0 deletions lib/sendEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// lib/sendEmail.ts
import nodemailer from 'nodemailer';

const transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASSWORD,
},
});

export const sendEmail = (to: string, subject: string, text: string) => {
const mailOptions = {
from: process.env.EMAIL_USERNAME,
to,
subject,
text,
};

return transporter.sendMail(mailOptions);
};

/* Notifications Backlog:
Backend:
Set up email sending using a service like SendGrid or Nodemailer.
Create API endpoints for managing notification preferences.
Frontend:
Create a notifications preferences page.
Implement UI for displaying notifications. */
Loading

0 comments on commit 96e3c70

Please sign in to comment.