Skip to content
Snippets Groups Projects
Commit 499e74c6 authored by Håkon Eilertsen Røskaft's avatar Håkon Eilertsen Røskaft
Browse files
parents 5f4befc3 0ebefce2
No related branches found
No related tags found
1 merge request!138Fix community leave
Showing
with 152 additions and 98 deletions
<template> <template>
<button <button
class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light" class="flex items-center px-2 py-2 font-medium tracking-wide capitalize text-white transition-colors duration-200 transform rounded-md focus:outline-none focus:ring focus:ring-opacity-80 min-w-{20px}"
:class="color"
> >
{{ text }} {{ text }}
</button> </button>
...@@ -11,6 +12,21 @@ export default { ...@@ -11,6 +12,21 @@ export default {
name: "ColoredButton", name: "ColoredButton",
props: { props: {
text: String, text: String,
buttonColor: {
type: String,
default: "blue",
},
},
computed: {
color() {
if (this.buttonColor === "red") {
return "bg-error-medium hover:bg-error-dark focus:ring-error-light";
}
if (this.buttonColor === "green") {
return "bg-success-medium hover:bg-success-dark focus:ring-success-light";
}
return "bg-primary-medium hover:bg-primary-dark focus:ring-primary-light";
},
}, },
}; };
</script> </script>
...@@ -25,10 +25,10 @@ ...@@ -25,10 +25,10 @@
>Administrer Gruppe</router-link >Administrer Gruppe</router-link
> >
</li> </li>
<li id="leaveGroup"> <li id="leaveGroup" v-if="!admin">
<div <div
class="cursor-pointer block py-2 px-4 text-sm text-error-medium hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white" class="cursor-pointer block py-2 px-4 text-sm text-error-medium hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
@click="leaveCommunity" @click="this.$emit('openLeaveCommunityDialog')"
> >
Forlat Gruppe Forlat Gruppe
</div> </div>
...@@ -38,8 +38,6 @@ ...@@ -38,8 +38,6 @@
</template> </template>
<script> <script>
import { LeaveCommunity } from "@/utils/apiutil";
export default { export default {
name: "CommunityHamburger", name: "CommunityHamburger",
data() { data() {
...@@ -49,13 +47,6 @@ export default { ...@@ -49,13 +47,6 @@ export default {
communityID: -1, communityID: -1,
}; };
}, },
methods: {
leaveCommunity: async function () {
this.id = this.$route.params.communityID;
await LeaveCommunity(this.id);
this.$router.push("/");
},
},
created() { created() {
this.communityID = this.$route.params.communityID; this.communityID = this.$route.params.communityID;
if (!Array.isArray(this.$store.state.user.adminList)) return; if (!Array.isArray(this.$store.state.user.adminList)) return;
......
<template> <template>
<div v-if="loading" class="flex place-content-center mx-4"> <div>
<LoaderSpinner /> <CustomFooterModal
</div> :title="'Er du sikker på at du vil forlate felleskapet?'"
<div v-else class="flex items-center justify-between mx-4"> :message="'Dersom felleskapet er låst er du nødt til å spørre om å bli med på nytt.'"
<router-link :visible="leaveDialog"
:to="'/community/' + community.communityId" @close="this.leaveDialog = false"
class="flex-1 min-w-0"
> >
<h2 <div class="flex place-content-center min-w-6">
class="text-xl md:text-2xl text-gray-600 font-medium w-full sm:truncate" <ColoredButton
> class="m-2"
{{ community.name }} :buttonColor="'red'"
</h2> @click="leaveCommunity()"
<div :text="'Ja'"
class="mt-1 flex flex-col sm:flex-row sm:flex-wrap sm:mt-0 sm:space-x-6" />
<ColoredButton
class="m-2"
:text="'Nei'"
@click="this.leaveDialog = false"
/>
</div>
</CustomFooterModal>
<div v-if="loading" class="flex place-content-center mx-4">
<LoaderSpinner />
</div>
<div v-else class="flex items-center justify-between mx-4">
<router-link
:to="'/community/' + community.communityId"
class="flex-1 min-w-0"
> >
<div class="mt-2 flex items-center text-sm text-gray-500"> <h2
class="text-xl md:text-2xl text-gray-600 font-medium w-full sm:truncate"
>
{{ community.name }}
</h2>
<div
class="mt-1 flex flex-col sm:flex-row sm:flex-wrap sm:mt-0 sm:space-x-6"
>
<div class="mt-2 flex items-center text-sm text-gray-500">
<svg
class="flex-shrink-0 mr-1.5 h-5 w-5 text-gray-400"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
>
<path
fill-rule="evenodd"
d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z"
clip-rule="evenodd"
/>
</svg>
{{ community.location }}
</div>
</div>
</router-link>
<div>
<!-- If the user is not a member in the community, this button will show -->
<div v-if="!member">
<ColoredButton
v-if="!member"
:text="'Bli med'"
@click="joinCommunity(community.communityId)"
class="m-2"
/>
<CustomFooterModal
@close="this.dialogOpen = false"
:visible="dialogOpen"
title="Kan ikke bli med"
message="Logg inn først for å bli med i en gruppe."
/>
</div>
<!-- If the user is member of the community, this hamburger menu will show -->
<div v-if="member">
<svg <svg
class="flex-shrink-0 mr-1.5 h-5 w-5 text-gray-400" @click="toggleHamburgerMenu()"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20" class="w-9 h-9 cursor-pointer"
fill="currentColor" fill="none"
aria-hidden="true" viewBox="0 0 24 24"
stroke="currentColor"
> >
<path <path
fill-rule="evenodd" stroke-linecap="round"
d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z" stroke-linejoin="round"
clip-rule="evenodd" stroke-width="2"
d="M4 6h16M4 12h16M4 18h16"
/> />
</svg> </svg>
{{ community.location }}
</div>
</div>
</router-link>
<div>
<!-- If the user is not a member in the community, this button will show -->
<div v-if="!member">
<ColoredButton
v-if="!member"
:text="'Bli med'"
@click="joinCommunity(community.communityId)"
class="m-2"
/>
<CustomFooterModal
@close="this.dialogOpen = false"
:visible="dialogOpen"
title="Kan ikke bli med"
message="Logg inn først for å bli med i en gruppe."
/>
</div>
<!-- If the user is member of the community, this hamburger menu will show --> <CommunityHamburger
<div v-if="member"> @openLeaveCommunityDialog="this.leaveDialog = true"
<svg v-if="hamburgerOpen"
@click="toggleHamburgerMenu()" class="origin-top-right absolute right-0"
xmlns="http://www.w3.org/2000/svg" :community-i-d="community.communityId"
class="w-9 h-9 cursor-pointer" :admin="admin"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4 6h16M4 12h16M4 18h16"
/> />
</svg> <!-- class="absolute" -->
</div>
<CommunityHamburger
v-if="hamburgerOpen"
class="origin-top-right absolute right-0"
:community-i-d="community.communityId"
:admin="admin"
/>
<!-- class="absolute" -->
</div> </div>
</div> </div>
</div> </div>
...@@ -88,6 +111,8 @@ import LoaderSpinner from "@/components/BaseComponents/LoaderSpinner"; ...@@ -88,6 +111,8 @@ import LoaderSpinner from "@/components/BaseComponents/LoaderSpinner";
import CommunityService from "@/services/community.service"; import CommunityService from "@/services/community.service";
import CustomFooterModal from "@/components/BaseComponents/CustomFooterModal"; import CustomFooterModal from "@/components/BaseComponents/CustomFooterModal";
import { parseCurrentUser } from "@/utils/token-utils"; import { parseCurrentUser } from "@/utils/token-utils";
import { LeaveCommunity } from "@/utils/apiutil";
import { import {
JoinOpenCommunity, JoinOpenCommunity,
// GetIfUserAlreadyInCommunity, // GetIfUserAlreadyInCommunity,
...@@ -109,10 +134,11 @@ export default { ...@@ -109,10 +134,11 @@ export default {
data() { data() {
return { return {
hamburgerOpen: false, hamburgerOpen: false,
dialogOpen: false, leaveDialog: false,
member: false, member: false,
community: {}, community: {},
loading: true, loading: true,
openDialog: false,
}; };
}, },
props: { props: {
...@@ -122,6 +148,10 @@ export default { ...@@ -122,6 +148,10 @@ export default {
toggleHamburgerMenu() { toggleHamburgerMenu() {
this.hamburgerOpen = !this.hamburgerOpen; this.hamburgerOpen = !this.hamburgerOpen;
}, },
leaveCommunity: async function () {
await LeaveCommunity(this.community.communityID);
this.$router.push("/");
},
async load() { async load() {
this.community = await CommunityService.getCommunity( this.community = await CommunityService.getCommunity(
this.$route.params.communityID this.$route.params.communityID
......
...@@ -55,6 +55,15 @@ class CommunityService { ...@@ -55,6 +55,15 @@ class CommunityService {
console.error(error); console.error(error);
}); });
} }
async leaveCommunity(communityID) {
return await axios.patch(
API_URL + "/communities/" + communityID + "/leave",
{
headers: tokenHeader(),
}
);
}
} }
export default new CommunityService(); export default new CommunityService();
...@@ -3,24 +3,31 @@ ...@@ -3,24 +3,31 @@
exports[`CommunityHeader component renders correctly 1`] = ` exports[`CommunityHeader component renders correctly 1`] = `
<div <div
adminstatus="true" adminstatus="true"
class="flex place-content-center mx-4"
community="[object Object]" community="[object Object]"
> >
<!-- Main modal -->
<!--v-if-->
<div <div
class="loadingio-spinner-bean-eater-o5tefvffeqm" class="flex place-content-center mx-4"
> >
<div <div
class="ldio-sweozsnwol" class="loadingio-spinner-bean-eater-o5tefvffeqm"
> >
<div> <div
<div /> class="ldio-sweozsnwol"
<div /> >
<div /> <div>
</div> <div />
<div> <div />
<div /> <div />
<div /> </div>
<div /> <div>
<div />
<div />
<div />
</div>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -152,6 +152,7 @@ exports[`CreateNewGroup elements rendering renders correctly 1`] = ` ...@@ -152,6 +152,7 @@ exports[`CreateNewGroup elements rendering renders correctly 1`] = `
class="flex justify-center mt-10 float-right" class="flex justify-center mt-10 float-right"
> >
<button-stub <button-stub
buttoncolor="blue"
id="saveButton" id="saveButton"
text="Lagre" text="Lagre"
/> />
......
...@@ -215,7 +215,7 @@ exports[`NewItemForm component renders correctly 1`] = ` ...@@ -215,7 +215,7 @@ exports[`NewItemForm component renders correctly 1`] = `
type="file" type="file"
/> />
<button <button
class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light" class="flex items-center px-2 py-2 font-medium tracking-wide capitalize text-white transition-colors duration-200 transform rounded-md focus:outline-none focus:ring focus:ring-opacity-80 min-w-{20px} bg-primary-medium hover:bg-primary-dark focus:ring-primary-light"
> >
Velg bilde Velg bilde
</button> </button>
...@@ -227,7 +227,7 @@ exports[`NewItemForm component renders correctly 1`] = ` ...@@ -227,7 +227,7 @@ exports[`NewItemForm component renders correctly 1`] = `
class="float-right" class="float-right"
> >
<button <button
class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light" class="flex items-center px-2 py-2 font-medium tracking-wide capitalize text-white transition-colors duration-200 transform rounded-md focus:outline-none focus:ring focus:ring-opacity-80 min-w-{20px} bg-primary-medium hover:bg-primary-dark focus:ring-primary-light"
id="saveButton" id="saveButton"
> >
Lagre Lagre
......
...@@ -49,7 +49,7 @@ exports[`LoginForm component renders correctly 1`] = ` ...@@ -49,7 +49,7 @@ exports[`LoginForm component renders correctly 1`] = `
Glemt passord? Glemt passord?
</router-link> </router-link>
<button <button
class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light login" class="flex items-center px-2 py-2 font-medium tracking-wide capitalize text-white transition-colors duration-200 transform rounded-md focus:outline-none focus:ring focus:ring-opacity-80 min-w-{20px} bg-primary-medium hover:bg-primary-dark focus:ring-primary-light login"
> >
Logg på Logg på
</button> </button>
......
...@@ -72,7 +72,7 @@ exports[`NewPasswordForm component renders correctly 1`] = ` ...@@ -72,7 +72,7 @@ exports[`NewPasswordForm component renders correctly 1`] = `
id="buttonsField" id="buttonsField"
> >
<button <button
class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light float-right" class="flex items-center px-2 py-2 font-medium tracking-wide capitalize text-white transition-colors duration-200 transform rounded-md focus:outline-none focus:ring focus:ring-opacity-80 min-w-{20px} bg-primary-medium hover:bg-primary-dark focus:ring-primary-light float-right"
> >
Sett ny passord Sett ny passord
</button> </button>
......
...@@ -86,7 +86,7 @@ exports[`RegisterFormComponent renders correctly 1`] = ` ...@@ -86,7 +86,7 @@ exports[`RegisterFormComponent renders correctly 1`] = `
class="flex justify-end mt-6" class="flex justify-end mt-6"
> >
<button <button
class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light" class="flex items-center px-2 py-2 font-medium tracking-wide capitalize text-white transition-colors duration-200 transform rounded-md focus:outline-none focus:ring focus:ring-opacity-80 min-w-{20px} bg-primary-medium hover:bg-primary-dark focus:ring-primary-light"
> >
Opprett Opprett
</button> </button>
......
...@@ -34,7 +34,7 @@ exports[`ResetPasswordForm component renders correctly 1`] = ` ...@@ -34,7 +34,7 @@ exports[`ResetPasswordForm component renders correctly 1`] = `
</div> </div>
<button <button
class="block text-white bg-primary-medium hover:bg-primary-dark focus:ring-4 focus:outline-none focus:ring-primary-light font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-medium dark:hover:bg-primary-dark dark:focus:ring-primary-light float-right" class="flex items-center px-2 py-2 font-medium tracking-wide capitalize text-white transition-colors duration-200 transform rounded-md focus:outline-none focus:ring focus:ring-opacity-80 min-w-{20px} bg-primary-medium hover:bg-primary-dark focus:ring-primary-light float-right"
> >
Tilbakestill passord Tilbakestill passord
</button> </button>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment