Add return path support for ticket creation and editing

This commit introduces support for a return path query parameter during ticket creation and editing operations. This enables a more user-friendly redirection after a form submission operation where the return path provides more context on the next page. The return path is now also considered in the Vue.js components, with necessary checks and validations. A 'Cancel' button has been added to the ActionToolbarComponent.vue where the return path exists.
This commit is contained in:
Julien Fastré 2024-05-31 22:23:13 +02:00
parent a9c0567ee1
commit d2a61ce69b
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
4 changed files with 34 additions and 3 deletions

View File

@ -63,8 +63,13 @@ final readonly class CreateTicketController
$this->entityManager->flush();
$query = [];
if ($request->query->has('returnPath')) {
$query['returnPath'] = $request->query->get('returnPath');
}
return new RedirectResponse(
$this->urlGenerator->generate('chill_ticket_ticket_edit', ['id' => $ticket->getId()])
$this->urlGenerator->generate('chill_ticket_ticket_edit', ['id' => $ticket->getId(), ...$query])
);
}
}

View File

@ -69,7 +69,6 @@ class Ticket implements TrackCreationInterface, TrackUpdateInterface
#[ORM\OneToMany(targetEntity: PersonHistory::class, mappedBy: 'ticket')]
private Collection $personHistories;
public function __construct()
{
$this->addresseeHistory = new ArrayCollection();

View File

@ -47,6 +47,9 @@
</div>
<div class="footer-ticket-main">
<ul class="nav nav-tabs justify-content-end">
<li v-if="hasReturnPath" class="nav-item p-2 go-back">
<a :href="returnPath" class="btn btn-cancel">Annuler</a>
</li>
<li class="nav-item p-2">
<button
type="button"
@ -157,6 +160,22 @@ export default defineComponent({
);
const users = computed(() => store.getters.getUsers as User[]);
const hasReturnPath = computed((): boolean => {
const params = new URL(document.location.toString()).searchParams;
return params.has('returnPath');
});
const returnPath = computed((): string => {
const params = new URL(document.location.toString()).searchParams;
const returnPath = params.get('returnPath');
if (null === returnPath) {
throw new Error("there isn't any returnPath, please check the existence before");
}
return returnPath;
})
const motive = ref(
ticket.value.currentMotive
? ticket.value.currentMotive
@ -217,6 +236,7 @@ export default defineComponent({
alert("Sera disponible plus tard");
}
return {
actionIcons: ref(store.getters.getActionIcons),
activeTab,
@ -229,12 +249,19 @@ export default defineComponent({
content,
submitAction,
handleClick,
hasReturnPath,
returnPath,
};
},
});
</script>
<style lang="scss" scoped>
.go-back {
margin-right: auto;
}
.sticky-form-buttons {
margin-top: 0px;
background: none;

View File

@ -16,7 +16,7 @@
import { defineComponent, ref, watch } from "vue";
import CKEditor from "@ckeditor/ckeditor5-vue";
import ClassicEditor from "../../../../../../../ChillMainBundle/Resources/public/module/ckeditor5";
import ClassicEditor from "../../../../../../../ChillMainBundle/Resources/public/module/ckeditor5/editor_config";
export default defineComponent({
name: "AddCommentComponent",