-
Notifications
You must be signed in to change notification settings - Fork 1
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
add connection for first part of reservation system for lyche #947
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -105,6 +105,7 @@ | |||||||
RecruitmentAdmissionForGangSerializer, | ||||||||
RecruitmentAdmissionForApplicantSerializer, | ||||||||
) | ||||||||
from .models.model_choices import ReservationOccasion | ||||||||
from .utils import event_query | ||||||||
|
||||||||
# =============================== # | ||||||||
|
@@ -310,6 +311,15 @@ class TableView(ModelViewSet): | |||||||
queryset = Table.objects.all() | ||||||||
|
||||||||
|
||||||||
class ReservationFormView(APIView): | ||||||||
permission_classes = [AllowAny] | ||||||||
|
||||||||
def get(self, request: Request) -> Response: | ||||||||
venue = self.request.query_params.get('venue', Venue.objects.get(slug='lyche').id) | ||||||||
biggest_table = Table.objects.filter(venue=venue).order_by('-seating').first() | ||||||||
return Response({'occasion': ReservationOccasion.choices, 'biggest_table': biggest_table.seating if biggest_table else 0}, status=status.HTTP_200_OK) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
|
||||||||
class ReservationCheckAvailabilityView(APIView): | ||||||||
permission_classes = [AllowAny] | ||||||||
serializer_class = ReservationCheckSerializer | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,50 +2,75 @@ import { Link } from '~/Components/Link/Link'; | |
import { SultenPage } from '~/Components/SultenPage'; | ||
import { TextItem } from '~/constants/TextItems'; | ||
import styles from './LycheReservationPage.module.scss'; | ||
import { toast } from 'react-toastify'; | ||
import { KV } from '~/constants'; | ||
import { useKeyValue, useTextItem } from '~/hooks'; | ||
import { ReservationDto } from '~/dto'; | ||
import { FetchAvailableTimesDto, ReservationDto } from '~/dto'; | ||
import { KEY } from '~/i18n/constants'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useState } from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
import { SamfForm } from '~/Forms/SamfForm'; | ||
import { SamfFormField } from '~/Forms/SamfFormField'; | ||
import { DropDownOption } from '~/Components/Dropdown/Dropdown'; | ||
import { ReservationFormLine } from './Components'; | ||
import { getAvailableTimes, getReservationForm } from '~/api'; | ||
import { dbT } from '~/utils'; | ||
import { STATUS } from '~/http_status_codes'; | ||
|
||
export function LycheReservationPage() { | ||
const { t } = useTranslation(); | ||
const sultenMail = useKeyValue(KV.SULTEN_MAIL); | ||
const [reservation, setReservation] = useState<ReservationDto>(); | ||
const [hoursOptions, setHoursOptions] = useState<DropDownOption<string>[]>(); | ||
const [occasionOptions, setOccasionOptions] = useState<DropDownOption<string>[]>(); | ||
const [occupancyOptions, setOccupancyOptions] = useState<DropDownOption<number>[]>(); | ||
const [availableDate, setAvailableDate] = useState<boolean>(false); | ||
|
||
const occasionOptions: DropDownOption<string>[] = [ | ||
{ value: 'DRINK', label: 'drikke' }, | ||
{ value: 'EAT', label: 'spise' }, | ||
]; | ||
|
||
const hoursOptions: DropDownOption<string>[] = [ | ||
{ value: '12:00', label: '12:00' }, | ||
{ value: '13:00', label: '13:00' }, | ||
{ value: '14:00', label: '14:00' }, | ||
{ value: '15:00', label: '15:00' }, | ||
]; | ||
|
||
const occupancyOptions: DropDownOption<number>[] = [ | ||
{ value: 1, label: '1' }, | ||
{ value: 2, label: '2' }, | ||
{ value: 3, label: '3' }, | ||
{ value: 4, label: '4' }, | ||
]; | ||
useEffect(() => { | ||
getReservationForm() | ||
.then((data) => { | ||
setOccasionOptions(data.occasion.map((d: string[]) => ({ value: d[0], label: d[1] }))); | ||
if (data.biggest_table == 0) { | ||
toast.error('Det eksisterer ingen bord i backend'); | ||
} else { | ||
Comment on lines
+33
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Antar dette bare er er for testing? |
||
setOccupancyOptions( | ||
new Array(data.biggest_table).fill(null).map((_, i) => ({ value: i + 1, label: (i + 1).toString() })), | ||
); | ||
} | ||
}) | ||
.catch((error) => { | ||
toast.error(t(KEY.common_something_went_wrong)); | ||
console.error(error); | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vi burde egt ikke ignorere disse |
||
}, []); | ||
|
||
function checkAvailableDate(data: ReservationDto) { | ||
setReservation({ ...reservation, ...data } as ReservationDto); | ||
setAvailableDate(true); | ||
getAvailableTimes(data as FetchAvailableTimesDto) | ||
.then((dateData: string[]) => { | ||
const transformed_hours = dateData.map((d: string) => ({ value: d, label: d })); | ||
setHoursOptions(transformed_hours); | ||
if (transformed_hours.length > 0) { | ||
setReservation(data); | ||
setAvailableDate(true); | ||
} else { | ||
toast.error(t(KEY.sulten_no_available_tables)); | ||
} | ||
}) | ||
.catch((e) => { | ||
if (e.response.status == STATUS.HTTP_406_NOT_ACCEPTABLE) { | ||
toast.error(dbT(e.response.data, 'error')); | ||
} else { | ||
toast.error(t(KEY.common_something_went_wrong)); | ||
} | ||
setAvailableDate(false); | ||
}); | ||
} | ||
|
||
function submit(data: ReservationDto) { | ||
console.log({ ...reservation, data }); | ||
} | ||
|
||
const findAvailableDateStage = ( | ||
<SamfForm | ||
className={styles.formContainer} | ||
|
@@ -87,7 +112,7 @@ export function LycheReservationPage() { | |
{t(KEY.common_date)} {reservation?.reservation_date as string} | ||
</p> | ||
<p className={styles.text}> | ||
{t(KEY.common_guests)} {reservation?.guest_count} | ||
{t(KEY.common_guests)}: {reservation?.guest_count} | ||
</p> | ||
</div> | ||
<ReservationFormLine label={t(KEY.common_time) + '*'}> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { | |
ClosedPeriodDto, | ||
EventDto, | ||
EventGroupDto, | ||
FetchAvailableTimesDto, | ||
FoodCategoryDto, | ||
FoodPreferenceDto, | ||
GangDto, | ||
|
@@ -20,6 +21,7 @@ import { | |
RecruitmentAdmissionDto, | ||
RecruitmentDto, | ||
RecruitmentPositionDto, | ||
ReservationFormDto, | ||
SaksdokumentDto, | ||
TextItemDto, | ||
UserDto, | ||
|
@@ -236,6 +238,20 @@ export async function getEventGroups(): Promise<EventGroupDto[]> { | |
return response.data; | ||
} | ||
|
||
export async function getAvailableTimes(data: FetchAvailableTimesDto, pk?: number): Promise<string[]> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pk først ser bedre ut There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skal ikke There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hvorfor er den optional i det hele tatt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Det er noe som ikke stemmer med dette endepunktet |
||
const url = BACKEND_DOMAIN + reverse({ pattern: ROUTES.backend.samfundet__check_reservation, urlParams: { pk: pk } }); | ||
const response = await axios.post<string[]>(url, data, { withCredentials: true }); | ||
|
||
return response.data; | ||
} | ||
|
||
export async function getReservationForm(): Promise<ReservationFormDto> { | ||
const url = BACKEND_DOMAIN + ROUTES.backend.samfundet__reservation_form; | ||
const response = await axios.get<ReservationFormDto>(url, { withCredentials: true }); | ||
|
||
return response.data; | ||
} | ||
|
||
export async function getMenus(): Promise<MenuDto[]> { | ||
const url = BACKEND_DOMAIN + ROUTES.backend.samfundet__menu_list; | ||
const response = await axios.get<MenuDto[]>(url, { withCredentials: true }); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disse burde vi samle som konstanter et sted (lyche etc)