Add room mutation to frontend
This commit is contained in:
parent
345b269435
commit
db61ca560a
|
|
@ -14,7 +14,11 @@
|
||||||
></room-colors>
|
></room-colors>
|
||||||
</div>
|
</div>
|
||||||
<div class="new-room__footer">
|
<div class="new-room__footer">
|
||||||
<button class="button button--primary new-room__save-button">Speichern</button>
|
<button
|
||||||
|
class="button button--primary new-room__save-button"
|
||||||
|
@click="addRoom(room)"
|
||||||
|
>Speichern
|
||||||
|
</button>
|
||||||
<button class="button">Abbrechen</button>
|
<button class="button">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -24,6 +28,9 @@
|
||||||
<script>
|
<script>
|
||||||
import RoomColors from '@/components/rooms/RoomColors';
|
import RoomColors from '@/components/rooms/RoomColors';
|
||||||
|
|
||||||
|
import ADD_ROOM_MUTATION from '@/graphql/gql/mutations/addRoom.gql';
|
||||||
|
import ROOMS_QUERY from '@/graphql/gql/roomsQuery.gql';
|
||||||
|
|
||||||
const defaultColor = 'blue';
|
const defaultColor = 'blue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -46,6 +53,28 @@
|
||||||
updateColor(newColor) {
|
updateColor(newColor) {
|
||||||
this.room.appearance = newColor;
|
this.room.appearance = newColor;
|
||||||
this.$store.dispatch('setSpecialContainerClass', newColor);
|
this.$store.dispatch('setSpecialContainerClass', newColor);
|
||||||
|
},
|
||||||
|
addRoom(room) {
|
||||||
|
this.$apollo.mutate({
|
||||||
|
mutation: ADD_ROOM_MUTATION,
|
||||||
|
variables: {
|
||||||
|
input: {
|
||||||
|
title: room.title,
|
||||||
|
description: room.description,
|
||||||
|
userGroup: 1,
|
||||||
|
appearance: room.appearance
|
||||||
|
}
|
||||||
|
},
|
||||||
|
update: (store, {data: {addRoom}}) => {
|
||||||
|
const data = store.readQuery({query: ROOMS_QUERY});
|
||||||
|
if (data.allRooms) {
|
||||||
|
data.allRooms.edges.push({node: addRoom});
|
||||||
|
store.writeQuery({query: ROOMS_QUERY, data});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
this.$router.push('/rooms');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
mutation AddRoomMutation($input: RoomMutationInput!) {
|
mutation AddRoomMutation($input: RoomMutationInput!) {
|
||||||
room(input: $input) {
|
addRoom(input: $input) {
|
||||||
id,
|
id
|
||||||
title,
|
title
|
||||||
slug,
|
slug
|
||||||
title,
|
title
|
||||||
description,
|
description
|
||||||
appearance,
|
appearance
|
||||||
clientMutationId,
|
userGroup
|
||||||
|
__typename
|
||||||
|
clientMutationId
|
||||||
errors {
|
errors {
|
||||||
field
|
field
|
||||||
messages
|
messages
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ query UserGroupsQuery {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
id
|
id
|
||||||
|
pk
|
||||||
name
|
name
|
||||||
year
|
year
|
||||||
isDeleted
|
isDeleted
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ data = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'title': 'Interview «Mein neues Umfeld»',
|
'title': 'Interview «Mein neues Umfeld»',
|
||||||
'appearance': 'brown'
|
'appearance': 'blue'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue