Skip to content

Commit

Permalink
Added some enhancements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud-Emad committed Nov 5, 2023
1 parent a09c810 commit 3fd4fb7
Show file tree
Hide file tree
Showing 20 changed files with 308 additions and 171 deletions.
11 changes: 5 additions & 6 deletions client/public/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,17 @@ h1, h2, h3, h4, h5, h6 {
color: white;
margin-top: 20px !important;
}
.event__birthday{
.event__birthday {
text-align: center;
color: white;
margin-top: -95px !important;
width: 30px;
margin-top: -100px !important;
width: 35px;
border-radius: 50%;
height: 30px;
height: 35px;
display: flex;
align-items: center;
justify-content: center;
margin-left: 125px;
/* padding: 20px; */
margin-left: 115px;
}
.p-relative{
position: relative;
Expand Down
16 changes: 10 additions & 6 deletions client/src/apis/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ class HomePage {
location: string;
}) {
try {
console.log("e: ", e);

if (
!e.name ||
!e.people ||
e.people.length === 0 ||
// !e.people ||
// e.people.length === 0 ||
!e.end_date ||
!e.location ||
// !e.location ||
!e.end_time ||
!e.from_time
)
throw new Error("Invalid data");
if (e.people.length === 0) throw new Error("No invited users");
// if (e.people.length === 0) throw new Error("No invited users");
let [fromHour, fromMinute] = e.from_time.split(":");
let [fromYear, fromMonth, fromDay] = e.from_date.split("-");
let [endHour, endMinute] = e.end_time.split(":");
Expand All @@ -49,7 +51,7 @@ class HomePage {
};

const data = {
people: e.people,
people: [],
from_date: {
year: Number(fromYear),
month: Number(fromMonth),
Expand All @@ -68,6 +70,8 @@ class HomePage {
description: e.description,
location: e.location,
};
console.log("data: ", data);

return await http.post("/event/", JSON.stringify(data));
} catch (error) {
console.error(
Expand All @@ -94,7 +98,7 @@ class HomePage {
!e.date
)
throw new Error("Invalid data");
if (e.invitedUsers.length === 0) throw new Error("No invited users");
// if (e.invitedUsers.length === 0) throw new Error("No invited users");
if (e.invitedUsers.includes(e.hostedUserID))
throw new Error("Hosted user is also invited");
let [hour, minute] = e.time.split(":");
Expand Down
6 changes: 6 additions & 0 deletions client/src/componants/calendar/CalendarDatePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
}
function validateDate(date: string): CalenderRequestFormResponseType {
console.log("Here....");
let validated: CalenderRequestFormResponseType = validateStartEndDates(
date,
startDate,
Expand All @@ -48,6 +50,8 @@
calculateActualVacationBalance()
}
errorMessage = validated.message
console.log(validated);
return validated
}
Expand Down Expand Up @@ -89,6 +93,7 @@
}}
size={20}
placeholder={'Start Date'}
disabled={true}
/>

{#if !onlyStart}
Expand All @@ -103,6 +108,7 @@
}}
size={20}
placeholder={'End Date'}
disabled={true}
/>
{/if}
<slot name="form" />
Expand Down
Empty file.
67 changes: 43 additions & 24 deletions client/src/componants/calendar/forms/EventForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
import Input from '../../ui/Input.svelte';
import ModalOpenButton from '../../ui/modals/ModalOpenButton.svelte';
import Modal from '../../ui/modals/SimpleModal.svelte';
import PeopleSelect from '../../ui/select/UsersMultiSelect.svelte';
// import PeopleSelect from '../../ui/select/UsersMultiSelect.svelte';
import type { SelectOptionType, calendarItemsType } from '../../../utils/types';
import CalendarDataService from '../../../apis/home/home';
import Submit from '../../ui/Button.svelte';
import { createEventDispatcher } from 'svelte';
import { isValidDate } from '../../../utils/validations';
export let startDate: string;
export let endDate: string;
export let datePickerDisabled = false;
let responseEvent: calendarItemsType;
let showToast: boolean = false;
const dispatch = createEventDispatcher();
let modalID = 11988731;
let eventLocationValue: string;
// let eventLocationValue: string;
let eventNameValue: string;
let eventDescriptionValue: string;
let eventFromTimeValue: string;
Expand All @@ -25,26 +27,26 @@
let eventDescriptionIsError: boolean | null = null;
let eventFromTimeIsError: boolean | null = null;
let eventEndTimeIsError: boolean | null = null;
let eventPeopleIsError: boolean | null = null;
// let eventPeopleIsError: boolean | null = null;
let peopleSelected: SelectOptionType[] = [];
// let peopleSelected: SelectOptionType[] = [];
let isLoading: boolean = false;
let isError: boolean = false;
// if true the disable submit button
let locationIsError: boolean | null = null;
$: fillDisabled =
locationIsError === null || locationIsError === true || datePickerDisabled;
// let locationIsError: boolean | null = null;
$: fillDisabled = !isValidDate(startDate) || !isValidDate(endDate)
// locationIsError === null || locationIsError === true || datePickerDisabled;
$: submitDisabled =
fillDisabled === true ||
// fillDisabled === true ||
eventNameIsError === null ||
eventNameIsError === true ||
eventDescriptionIsError === null ||
eventDescriptionIsError === true ||
eventFromTimeIsError === true ||
datePickerDisabled ||
eventEndTimeIsError === true ||
peopleSelected.length === 0;
eventEndTimeIsError === true
// peopleSelected.length === 0;
const modalData = {
'data-bs-dismiss': 'modal',
Expand All @@ -54,7 +56,7 @@
</script>

<div>
<Input
<!-- <Input
type="text"
label={'Location'}
bind:value={eventLocationValue}
Expand All @@ -66,7 +68,7 @@
hint={'please write proper location'}
placeholder={'write event location'}
bind:isError={locationIsError}
/>
/> -->
<div class="width-100 mt-4">
<ModalOpenButton width={100} label="Fill" disabled={fillDisabled} {modalID} />
</div>
Expand All @@ -79,17 +81,24 @@
isFooter={true}
doneText={'Done'}
deleteText={'Delete'}
on:close={() => {
eventNameValue = null;
eventDescriptionValue = null;
eventFromTimeValue = null;
eventEndTimeValue = null;
eventNameIsError = null;
eventDescriptionIsError = null;
eventFromTimeIsError = null;
eventEndTimeIsError = null;
isError = false;
}}
>
<header slot="header">
<h6>🎉 Event Form</h6>
</header>

<form slot="form">
{#if isError}
<div class="alert alert-danger" role="alert">
<strong>Oh snap!</strong> Change a few things up and try submitting again.
</div>
{:else if isLoading}
{#if isLoading}
<div class="alert alert-info" role="alert">
<strong>Loading...</strong> Please wait.
</div>
Expand Down Expand Up @@ -147,11 +156,17 @@
placeholder={'write event time'}
bind:isError={eventEndTimeIsError}
/>
<PeopleSelect
<!-- <PeopleSelect
isTop={true}
bind:isError={eventPeopleIsError}
bind:selected={peopleSelected}
/>
/> -->
{/if}

{#if isError}
<div class="mt-4 alert alert-danger" role="alert">
<strong>Oh snap!</strong> Change a few things up and try submitting again.
</div>
{/if}
</form>
<div slot="submit">
Expand All @@ -160,16 +175,19 @@
errorMessage={eventNameValue + ' Event Submission Failed'}
{modalData}
label="Post Event!"
bind:show={showToast}
onClick={async () => {
isLoading = true;
try {
let selected = peopleSelected.map((item) => Number(item.value));
isError = false;
// let selected = peopleSelected.map((item) => Number(item.value));
// location: eventLocationValue,
const axios = await CalendarDataService.postEvent({
location: '',
description: eventDescriptionValue,
end_time: eventEndTimeValue,
location: eventLocationValue,
name: eventNameValue,
people: selected,
people: [],
end_date: endDate,
from_date: startDate,
from_time: eventFromTimeValue,
Expand All @@ -182,11 +200,12 @@
} catch (error) {
isError = true;
} finally {
showToast = true;
isLoading = false;
eventDescriptionValue = '';
eventEndTimeValue = '';
eventLocationValue = '';
peopleSelected = [];
// eventLocationValue = '';
// peopleSelected = [];
}
return isError;
}}
Expand Down
17 changes: 15 additions & 2 deletions client/src/componants/calendar/forms/LeaveForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$: submitDisabled =
selectedReason == 0 || datePickerDisabled == true
selectedReason == 0 || datePickerDisabled == true || calculatorValue === 0
</script>

Expand All @@ -55,7 +55,16 @@
{/if}
{#if showCalclator}
<div class="alert alert-light p-0 text-center">
Actual value after deducting weekend holidays {calculatorValue}
<br />
{#if calculatorValue === 0}
<small class="text-red">
" It seems like the chosen day might be a holiday or a weekend break. Please verify this on your calendar. "
</small>
{:else}
<small class="text-dark">
The final count after excluding weekends and holidays is {calculatorValue} { calculatorValue > 1 ? 'days' : 'day'}.
</small>
{/if}
</div>
{/if}
{#if withSubmit}
Expand All @@ -67,6 +76,7 @@
onClick={async () => {
isLoading = true;
try {
isError = false;
if(isUpdate && vacationID != ""){
const axios = await Vacations.update(vacationID, {
end_date: endDate,
Expand Down Expand Up @@ -126,6 +136,9 @@
border-radius: 0.375rem;
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
.text-red{
color: red;
}
select{
margin-top: 0.3cm;
background-color: var(--secondary-color);
Expand Down
Loading

0 comments on commit 3fd4fb7

Please sign in to comment.