Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michal Čížek
flea-market-manager
Commits
7f4e2ca2
Commit
7f4e2ca2
authored
May 18, 2022
by
Lucia Lopuchova
Committed by
cizek
May 18, 2022
Browse files
Add cancel function to user reservations
parent
c14c3a0e
Changes
7
Show whitespace changes
Inline
Side-by-side
frontend/src/models/stand-reservation.ts
deleted
100644 → 0
View file @
c14c3a0e
export
type
StandReservation
=
{
standId
:
string
;
itemCategories
:
string
[];
standTypeName
:
string
;
eventName
:
string
;
startDate
:
string
;
}
\ No newline at end of file
frontend/src/models/stand.ts
View file @
7f4e2ca2
...
...
@@ -6,4 +6,5 @@ export type Stand = {
itemCategories
:
string
[];
standType
:
StandType
;
seller
?:
User
|
null
;
eventId
:
string
;
};
frontend/src/models/user-stand-reservation.ts
0 → 100644
View file @
7f4e2ca2
import
{
StandType
}
from
"
./stand-type
"
;
import
{
User
}
from
"
./user
"
;
export
type
UserStandReservation
=
{
id
:
string
;
itemCategories
:
string
[];
standType
:
StandType
;
seller
:
User
;
eventId
:
string
;
eventName
:
string
;
startDate
:
string
;
}
\ No newline at end of file
frontend/src/modules/stand-reservation/reservation-columns.ts
View file @
7f4e2ca2
import
{
TableColumn
}
from
"
components/table/types
"
;
import
{
StandReservation
}
from
"
../../models/stand-reservation
"
;
import
{
UserStandReservation
}
from
"
../../models/user-stand-reservation
"
;
import
{
ReservationsActionCell
}
from
"
./reservations-action-cell
"
;
export
const
reservationColumns
:
TableColumn
<
StandReservation
>
[]
=
[
export
const
reservationColumns
:
TableColumn
<
User
StandReservation
>
[]
=
[
{
key
:
"
standType
Name
"
,
key
:
"
standType
"
,
label
:
"
Stand Type
"
,
render
:
({
standType
Name
})
=>
standType
N
ame
,
render
:
({
standType
})
=>
standType
.
n
ame
,
},
{
key
:
"
itemCategories
"
,
...
...
@@ -21,5 +22,10 @@ export const reservationColumns: TableColumn<StandReservation>[] = [
key
:
"
startDate
"
,
label
:
"
Start Date
"
,
render
:
({
startDate
})
=>
startDate
},
{
key
:
"
actions
"
,
label
:
"
Actions
"
,
Cell
:
ReservationsActionCell
}
];
\ No newline at end of file
frontend/src/modules/stand-reservation/reservation-table.tsx
View file @
7f4e2ca2
...
...
@@ -4,6 +4,7 @@ import { getUserReservations } from "./stand-reservation-api";
import
{
Container
}
from
"
@mantine/core
"
;
import
{
Table
}
from
"
components/table/table
"
;
import
{
reservationColumns
}
from
"
./reservation-columns
"
;
import
{
UserStandReservation
}
from
"
../../models/user-stand-reservation
"
;
interface
Props
{
userId
:
string
;
...
...
@@ -12,7 +13,7 @@ interface Props {
export
const
ReservationTable
=
({
userId
}:
Props
)
=>
{
const
{
showNotification
}
=
useNotification
();
const
{
data
,
isLoading
}
=
useQuery
([
"
userId
"
,
userId
],
()
=>
getUserReservations
(
userId
),
{
const
{
data
,
isLoading
}
=
useQuery
<
UserStandReservation
[]
>
([
"
userReservations
"
,
userId
],
()
=>
getUserReservations
(
userId
),
{
onError
:
()
=>
{
showNotification
({
content
:
"
Reservations failed to load
"
,
...
...
frontend/src/modules/stand-reservation/reservations-action-cell.tsx
0 → 100644
View file @
7f4e2ca2
import
{
TableCellProps
}
from
"
../../components/table/types
"
;
import
{
useNotification
}
from
"
../../context/notification/notification-context
"
;
import
{
useMutation
,
useQueryClient
}
from
"
react-query
"
;
import
{
cancelReservation
}
from
"
./stand-reservation-api
"
;
import
{
useCallback
}
from
"
react
"
;
import
{
UserStandReservation
}
from
"
../../models/user-stand-reservation
"
;
import
{
Stand
}
from
"
../../models/stand
"
;
import
{
ActionIcon
,
Group
}
from
"
@mantine/core
"
;
import
{
Trash
}
from
"
tabler-icons-react
"
;
export
const
ReservationsActionCell
=
({
row
}:
TableCellProps
<
UserStandReservation
>
)
=>
{
const
{
showNotification
}
=
useNotification
();
const
queryClient
=
useQueryClient
();
const
cancelMutation
=
useMutation
(
cancelReservation
,
{
onError
:
()
=>
{
showNotification
({
content
:
"
Cancelling reservation failed
"
,
variant
:
"
error
"
,
});
},
onSuccess
:
()
=>
{
showNotification
({
content
:
"
Reservation cancelled
"
,
variant
:
"
success
"
,
});
},
onSettled
:
()
=>
{
queryClient
.
invalidateQueries
(
"
userReservations
"
);
},
});
const
handleCancel
=
useCallback
(()
=>
{
const
stand
:
Stand
=
{
id
:
row
.
id
,
standType
:
row
.
standType
,
itemCategories
:
row
.
itemCategories
.
map
(
category
=>
category
.
toUpperCase
()),
seller
:
undefined
,
eventId
:
row
.
eventId
}
cancelMutation
.
mutate
(
stand
)
},
[
cancelMutation
,
row
]);
return
(
<
Group
spacing
=
"xs"
>
<
ActionIcon
variant
=
"hover"
onClick
=
{
handleCancel
}
>
<
Trash
color
=
"red"
/>
</
ActionIcon
>
</
Group
>
)
}
\ No newline at end of file
frontend/src/modules/stand-reservation/stand-reservation-api.ts
View file @
7f4e2ca2
...
...
@@ -2,6 +2,7 @@ import axios from "axios";
import
{
apiUrl
}
from
"
constants/api-url
"
;
import
{
Reservation
}
from
"
./stand-resevation-type
"
;
import
{
Stand
}
from
"
../../models/stand
"
;
export
const
getItemCategories
=
async
()
=>
axios
.
get
(
`
${
apiUrl
}
/stands/item-categories/list`
).
then
((
res
)
=>
res
.
data
);
...
...
@@ -14,3 +15,6 @@ export const putReservation = ( args: {marketEventId: string, values: Reservatio
export
const
getUserReservations
=
async
(
userId
:
string
)
=>
axios
.
get
(
`
${
apiUrl
}
/stands/list/user/
${
userId
}
`
).
then
((
res
)
=>
res
.
data
)
export
const
cancelReservation
=
async
(
stand
:
Stand
)
=>
axios
.
put
(
`
${
apiUrl
}
/stands/
${
stand
.
id
}
`
,
stand
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment