Skip to content

Commit

Permalink
feat(vue): Add temp snackbar after edit success
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Ribiere committed Oct 8, 2024
1 parent 5260f88 commit 22d9588
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
7 changes: 7 additions & 0 deletions vue/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
<DialogController />
</KeepAlive>
<EditContentDialog />
<v-snackbar
v-model="appStore.showSnackBar"
color="main-green"
:timeout="2000"
>
{{ appStore.snackBarMessage }}
</v-snackbar>
<div :class="'App__content container ' + (appStore.mobile ? 'App__content--mobile' : 'App__content--desktop')">
<v-breadcrumbs v-if="!appStore.mobile" :items="appStore.breadcrumbs"></v-breadcrumbs>
<RouterView />
Expand Down
12 changes: 0 additions & 12 deletions vue/src/components/views-components/actors/ActorEditionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ const {form, handleSubmit, isSubmitting} = ActorsFormService.getActorsForm(actor
const categoryItems = Object.values(ActorsCategories)
const expertisesItems = actorsStore.actorsExpertises
onMounted(() => {
console.log(expertisesItems)
})
const thematicsItems = actorsStore.actorsThematics
const administrativeScopesItems = actorsStore.actorsAdministrativesScopes
Expand All @@ -196,20 +193,11 @@ function handleFilesUpdate(files: (ContentImageFromUserFile | ContentImageFromUr
selectedFiles.value = files;
}
// const submitForm = handleSubmit((values) => {
// const actorSubmission: ActorSubmission = {
// ...values, imagesToUpload: [...selectedFiles.value]
// }
// console.log(actorSubmission)
// actorsStore.createActor(actorSubmission)
// })
const submitForm = handleSubmit(
values => {
const actorSubmission: ActorSubmission = {
...values, imagesToUpload: [...selectedFiles.value]
}
console.log(actorSubmission)
actorsStore.createOrEditActor(actorSubmission, actorToEdit !== null)
},
errors => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const isEditable = computed(() => {
})
function editActor(actor: Actor) {
actorsStore.activateActorEdition(actor)
actorsStore.setActorEditionMode(actor)
}
</script>
<style lang="scss">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div class="Admin__actorsPanel__content__item__type">Type d'acteur</div>
<div class="Admin__actorsPanel__content__item__actions">
<template v-if="!actor.isValidated">
<v-btn size="small" icon="mdi-arrow-right" class="text-main-blue" @click="actorsStore.activateActorEdition(actor.id)"></v-btn>
<v-btn size="small" icon="mdi-arrow-right" class="text-main-blue" @click="actorsStore.setActorEditionMode(actor)"></v-btn>
</template>
<template v-else>
<v-btn icon="mdi-pencil-outline"></v-btn>
Expand All @@ -57,7 +57,7 @@ const actorsCount = computed(() => actorsStore.actors.length)
const sortingActorsSelectedMethod = ref("isValidated")
const createActor = () => {
actorsStore.activateActorEdition(null)
actorsStore.setActorEditionMode(null)
}
const sortedActors = computed(() => {
if (sortingActorsSelectedMethod.value === "isValidated") {
Expand Down
2 changes: 1 addition & 1 deletion vue/src/components/views-components/header/LoginButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<v-list-item-title>{{ $t('header.addProject') }}</v-list-item-title>
</v-list-item>
<v-list-item v-if="userStore.userHasRole(UserRoles.EDITOR_ACTORS) || userStore.userIsAdmin()"
@click="actorsStore.activateActorEdition(null)"
@click="actorsStore.setActorEditionMode(null)"
>
<template v-slot:prepend>
<v-icon color="main-blue" icon="mdi-pencil-outline"></v-icon>
Expand Down
2 changes: 1 addition & 1 deletion vue/src/components/views/ActorsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const paginatedActors = computed(() => {
const totalPages = computed(() => Math.ceil(actorsStore.actors.length / itemsPerPage));
function addActor() {
actorsStore.activateActorEdition(null);
actorsStore.setActorEditionMode(null);
}
function searchActors(value: string, queryText: string, itemText: any) {
Expand Down
12 changes: 7 additions & 5 deletions vue/src/stores/actorsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ export const useActorsStore = defineStore(StoresList.ACTORS, () => {
active: false,
actor: null
})
function activateActorEdition(actor: Actor | null) {
function setActorEditionMode(actor: Actor | null) {
actorEdition.actor = actor
actorEdition.active = true
useApplicationStore().showEditContentDialog = true
actorEdition.active = actor !== null
useApplicationStore().showEditContentDialog = actor !== null
}

async function createOrEditActor(actor: Actor, edit: boolean) {
const id = selectedActor.value?.id
const post = await ActorsService.createOrEditActor(actor, edit, id)
console.log(post)
setActorEditionMode(null)
useApplicationStore().snackBarMessage = edit ? 'L\'acteur a bien été modifié' : 'L\'acteur a bien été ajouté'
useApplicationStore().showSnackBar = true
}

return {
Expand All @@ -60,7 +62,7 @@ export const useActorsStore = defineStore(StoresList.ACTORS, () => {
getActorsSelectListContent,
setSelectedActor,
actorEdition,
activateActorEdition,
setActorEditionMode,
createOrEditActor
}
})
5 changes: 4 additions & 1 deletion vue/src/stores/applicationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ export const useApplicationStore = defineStore(StoresList.APPLICATION, () => {
activeTab.value = NavigationTabsService.getTabsNumberFromRoute(route, activeTab.value)
return BreadcrumbsService.getBreadcrumbsItems(route)
})
return { mobile, activeTab, activeDialog, breadcrumbs, showEditContentDialog }

const showSnackBar = ref(false)
const snackBarMessage = ref('')
return { mobile, activeTab, activeDialog, breadcrumbs, showEditContentDialog, showSnackBar, snackBarMessage }
})

0 comments on commit 22d9588

Please sign in to comment.