Skip to content

Commit

Permalink
Merge pull request #56 from ConducereIT/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
cristim67 authored Apr 12, 2024
2 parents f33df10 + 2ee0734 commit 197a3a3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
8 changes: 7 additions & 1 deletion client/src/components/RaceRegistration.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ const RaceRegistration: React.FC = () => {
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
await BackendService.addRaces(registration.race, registration.phoneNumber, registration.tshirtSize, registration.paymentMethod);
const response = await BackendService.addRaces(registration.race, registration.phoneNumber, registration.tshirtSize, registration.paymentMethod);
console.log(response);
if(response.status === 200) {
alert('Înscrierea a fost realizată cu succes!');
window.location.href = '/';
}
if(response.status === 400) {
alert(response.message);
}
} catch (error) {
alert('A apărut o eroare la înscriere. Vă rugăm să încercați din nou.');
}
Expand Down
71 changes: 39 additions & 32 deletions client/src/views/Account.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ const Account: React.FC = () => {
const [userName, setUserName] = useState<string>("");
const [races, setRaces] = useState<Race[]>([]);
const navigate = useNavigate();

const [userPicture, setUserPicture] = useState<string>("");
useEffect(() => {
const isLoggedIn = async () => {
try {
const response = await AuthService.getInstance().userInfoForToken(
localStorage.getItem("token") as string,
);
setUserName(response.name!);
// @ts-expect-error This line may temporarily cause a type error due to external dependencies.
setUserPicture(response.profilePictureUrl!);
} catch (error) {
console.log("Not logged in", error);
navigate("/login");
Expand Down Expand Up @@ -63,38 +65,43 @@ const Account: React.FC = () => {
<Header />
<div className="bg-white rounded-lg shadow-md mx-auto max-w-7xl mt-48 p-6">
<h1 className="text-xl mb-6 font-semibold flex justify-center">Profil - {userName}</h1>
<h2 className="text-2xl font-semibold mb-6 flex justify-center">Cursele la care te-ai înscris</h2>
<img src={userPicture} alt="profile" className="mx-auto rounded-full w-26 h-26" />
{
races.length === 0 ? (
<div className="flex flex-col items-center">
<h3 className="text-xl font-semibold mt-4">Nu te-ai înscris încă la nicio cursă.</h3>
<h3 className="text-xl font-semibold mb-6 mt-8">Dorești să te înscrii la o nouă cursă?</h3>
<button
className="bg-[#006470] text-white font-semibold py-2 px-2 md:py-2 md:px-4 rounded-lg uppercase tracking-wide hover:bg-teal-500 focus:outline-none focus:ring transition duration-300 w-[10rem] md:w-[12rem]"
onClick={() => navigate("/register-race")}
> Adaugă cursă
</button>
</div>
) : (
<div className="overflow-x-auto mt-4">
<h2 className="text-2xl font-semibold mb-6 flex justify-center">Cursa la care te-ai înscris</h2>
<table className="table-auto border border-collapse border-gray-200 mx-auto">
<thead className="bg-gray-200">
<tr className="bg-gray-200">
<th className="px-4 py-2">Categorie</th>
<th className="px-4 py-2">Numar Tricou</th>
<th className="px-4 py-2">Timp Alergat</th>
</tr>
</thead>
<tbody>
{races.map((race, index) => (
<tr key={index} className={index % 2 === 0 ? 'bg-gray-100' : ''}>
<td className="px-4 py-2">{racesContext[race.categorie]}</td>
<td className="px-4 py-2">{race.numarTricou ? race.numarTricou : 'N/A'}</td>
<td className="px-4 py-2">{race.timpAlergat ? race.timpAlergat : 'N/A'}</td>
</tr>
))}
</tbody>
</table>
</div>
)
}

<div className="overflow-x-auto">
<table className="table-auto border border-collapse border-gray-200 mx-auto">
<thead className="bg-gray-200">
<tr className="bg-gray-200">
<th className="px-4 py-2">Nr</th>
<th className="px-4 py-2">Categorie</th>
<th className="px-4 py-2">Numar Tricou</th>
<th className="px-4 py-2">Timp Alergat</th>
</tr>
</thead>
<tbody>
{races.map((race, index) => (
<tr key={index} className={index % 2 === 0 ? 'bg-gray-100' : ''}>
<td className="px-4 py-2">{race.id}</td>
<td className="px-4 py-2">{racesContext[race.categorie]}</td>
<td className="px-4 py-2">{race.numarTricou ? race.numarTricou : 'N/A'}</td>
<td className="px-4 py-2">{race.timpAlergat ? race.timpAlergat : 'N/A'}</td>
</tr>
))}
</tbody>
</table>
</div>
<div className="flex flex-col items-center">
<h3 className="text-xl font-semibold mb-6 mt-8">Dorești să te înscrii la o nouă cursă?</h3>
<button
className="bg-[#006470] text-white font-semibold py-2 px-2 md:py-2 md:px-4 rounded-lg uppercase tracking-wide hover:bg-teal-500 focus:outline-none focus:ring transition duration-300 w-[10rem] md:w-[12rem]"
onClick={() => navigate("/register-race")}
> Adaugă cursă
</button>
</div>
</div>
</>
)
Expand Down

0 comments on commit 197a3a3

Please sign in to comment.