disable optimization request btn if already sent
This commit is contained in:
parent
77a0a42606
commit
c73b9d671b
7 changed files with 114 additions and 81 deletions
|
|
@ -1,20 +1,21 @@
|
|||
<?php
|
||||
|
||||
$project = [
|
||||
"title" => $page->title()->value(),
|
||||
"url" => $page->url(),
|
||||
"modified" => $page->modified("Y-MM-d"),
|
||||
"status" => $page->status(),
|
||||
"logo" => $page->client()->isNotEmpty() && $page->client()->toPage()
|
||||
'title' => $page->title()->value(),
|
||||
'url' => $page->url(),
|
||||
'modified' => $page->modified('Y-MM-d'),
|
||||
'status' => $page->status(),
|
||||
'logo' => $page->client()->isNotEmpty() && $page->client()->toPage()
|
||||
? $page->client()->toPage()->logo()->toFile()->url()
|
||||
: null,
|
||||
"steps" => $page->getSteps(),
|
||||
"designToLight" => $page->isDTLEnabled() == "true" ? processDTLProposals($page) : null,
|
||||
'steps' => $page->getSteps(),
|
||||
'designToLight' => $page->isDTLEnabled()->isTrue() ? processDTLProposals($page) : null,
|
||||
'hasOptimizationRequest' => $page->hasOptimizationRequest()->isTrue(),
|
||||
];
|
||||
|
||||
$pageData = array_merge($genericData, $project);
|
||||
|
||||
echo json_encode([
|
||||
"page" => $pageData,
|
||||
"user" => $userData,
|
||||
'page' => $pageData,
|
||||
'user' => $userData,
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -1,41 +1,44 @@
|
|||
<?php
|
||||
function getProjectData($project) {
|
||||
|
||||
function getProjectData($project)
|
||||
{
|
||||
$data = [
|
||||
"title" => $project->title()->value(),
|
||||
"url" => $project->url(),
|
||||
"uri" => "/" . $project->uri(),
|
||||
"modified" => $project->modified("Y-MM-d"),
|
||||
"currentStep" => $project->currentStep()->value(),
|
||||
"status" => $project->status(),
|
||||
"logo" => $project->client()->toPage() ? $project->client()->toPage()->logo()->toFile()->url() : "",
|
||||
"steps" => $project->getSteps(),
|
||||
"notifications" => Yaml::decode($project->notifications()->value),
|
||||
"uuid" => (string) $project->uuid(),
|
||||
"slug" => (string) $project->slug(),
|
||||
"isDTLEnabled" => $project->isDTLEnabled()->value() == "true" ? true : false
|
||||
'title' => $project->title()->value(),
|
||||
'url' => $project->url(),
|
||||
'uri' => '/' . $project->uri(),
|
||||
'modified' => $project->modified('Y-MM-d'),
|
||||
'currentStep' => $project->currentStep()->value(),
|
||||
'status' => $project->status(),
|
||||
'logo' => $project->client()->toPage() ? $project->client()->toPage()->logo()->toFile()->url() : '',
|
||||
'steps' => $project->getSteps(),
|
||||
'notifications' => Yaml::decode($project->notifications()->value),
|
||||
'uuid' => (string) $project->uuid(),
|
||||
'slug' => (string) $project->slug(),
|
||||
'isDTLEnabled' => $project->isDTLEnabled()->isTrue(),
|
||||
'hasOptimizationRequest' => $project->hasOptimizationRequest()->isTrue(),
|
||||
];
|
||||
|
||||
if ($project->isDTLEnabled()) {
|
||||
$data["designToLight"] = processDTLProposals($project);
|
||||
$data['designToLight'] = processDTLProposals($project);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
try {
|
||||
$children = $kirby->user()->role() == "admin" ? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project))->values() : $kirby->user()->projects()->toPages()->map(fn($project) => getProjectData($project))->values();
|
||||
$children = $kirby->user()->role() == 'admin' ? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project))->values() : $kirby->user()->projects()->toPages()->map(fn($project) => getProjectData($project))->values();
|
||||
} catch (\Throwable $th) {
|
||||
throw new Exception($th->getMessage() . " line " . $th->getLine(), 1);
|
||||
throw new Exception($th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||
$children = [];
|
||||
}
|
||||
|
||||
$specificData = [
|
||||
"children" => $children,
|
||||
'children' => $children,
|
||||
];
|
||||
|
||||
$pageData = array_merge($genericData, $specificData);
|
||||
|
||||
echo json_encode([
|
||||
"page" => $pageData,
|
||||
"user" => $userData
|
||||
'page' => $pageData,
|
||||
'user' => $userData,
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
proposals.length === 1 && isDialogOpen
|
||||
? activeProposal.title
|
||||
? activeProposal.title
|
||||
: "Design to light"
|
||||
: "Design to light"
|
||||
: 'Design to light'
|
||||
: 'Design to light'
|
||||
}}
|
||||
</h2>
|
||||
<button
|
||||
|
|
@ -41,8 +41,8 @@
|
|||
proposal.title
|
||||
? proposal.title
|
||||
: index === 0
|
||||
? "Proposition initiale"
|
||||
: "Alternative " + index
|
||||
? 'Proposition initiale'
|
||||
: 'Alternative ' + index
|
||||
}}
|
||||
</button>
|
||||
</nav>
|
||||
|
|
@ -163,11 +163,15 @@
|
|||
</div>
|
||||
<footer v-if="proposals.length === 1 && !isDialogOpen" class="p-16">
|
||||
<button
|
||||
disabled
|
||||
:disabled="page.hasOptimizationRequest ? '' : undefined"
|
||||
class="btn btn--white w-full"
|
||||
@click="handleOptimizationButtonClick"
|
||||
>
|
||||
Demander une expertise d’optimisation
|
||||
{{
|
||||
page.hasOptimizationRequest
|
||||
? "Demande d'expertise en cours de traitement…"
|
||||
: 'Demander une expertise d’optimisation'
|
||||
}}
|
||||
</button>
|
||||
</footer>
|
||||
</section>
|
||||
|
|
@ -178,18 +182,19 @@
|
|||
/>
|
||||
</template>
|
||||
<script setup>
|
||||
import OptimizationRequestDialog from "./OptimizationRequestDialog.vue";
|
||||
import dayjs from "dayjs";
|
||||
import "dayjs/locale/fr";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { ref, onBeforeUnmount, computed } from "vue";
|
||||
import { useDialogStore } from "../../stores/dialog";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import OptimizationRequestDialog from './OptimizationRequestDialog.vue';
|
||||
import dayjs from 'dayjs';
|
||||
import 'dayjs/locale/fr';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ref, onBeforeUnmount, computed } from 'vue';
|
||||
import { useDialogStore } from '../../stores/dialog';
|
||||
import { usePageStore } from '../../stores/page';
|
||||
|
||||
const { proposals } = defineProps({
|
||||
proposals: Array,
|
||||
});
|
||||
|
||||
const { page } = storeToRefs(usePageStore());
|
||||
const { openedFile } = storeToRefs(useDialogStore());
|
||||
|
||||
const isDialogOpen = computed(() => {
|
||||
|
|
@ -202,29 +207,29 @@ const isDialogOpen = computed(() => {
|
|||
|
||||
const isOptimizationDialogOpen = ref(false);
|
||||
|
||||
dayjs.locale("fr");
|
||||
dayjs.locale('fr');
|
||||
|
||||
const emits = defineEmits(["close"]);
|
||||
const emits = defineEmits(['close']);
|
||||
|
||||
proposals[0].isActive = true;
|
||||
|
||||
const activeProposal = ref(proposals[0]);
|
||||
|
||||
window.addEventListener("keyup", closeOnEscape);
|
||||
window.addEventListener("click", close);
|
||||
window.addEventListener('keyup', closeOnEscape);
|
||||
window.addEventListener('click', close);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("keyup", closeOnEscape);
|
||||
window.removeEventListener("click", close);
|
||||
window.removeEventListener('keyup', closeOnEscape);
|
||||
window.removeEventListener('click', close);
|
||||
});
|
||||
|
||||
// Functions
|
||||
function closeOnEscape(event) {
|
||||
if (event.key === "Escape") emits("close");
|
||||
if (event.key === 'Escape') emits('close');
|
||||
}
|
||||
|
||||
function close() {
|
||||
emits("close");
|
||||
emits('close');
|
||||
}
|
||||
|
||||
function preventClose(event) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
header="Demander un rendez-vous"
|
||||
class="dialog"
|
||||
:closeOnEscape="true"
|
||||
@click="preventClose($event)"
|
||||
>
|
||||
<template #header>
|
||||
<h2 class="font-serif text-lg">Demander un rendez-vous</h2>
|
||||
|
|
@ -34,6 +35,7 @@
|
|||
v-for="project in currentProjects"
|
||||
:key="project.uri"
|
||||
:value="project.uri.substring(1)"
|
||||
:disabled="project.hasOptimizationRequest ? '' : undefined"
|
||||
>
|
||||
{{ project.title }}
|
||||
</option>
|
||||
|
|
@ -74,26 +76,33 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import Dialog from "primevue/dialog";
|
||||
import { useApiStore } from "../../stores/api";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useProjectsStore } from "../../stores/projects";
|
||||
import { ref, watch } from "vue";
|
||||
import Dialog from 'primevue/dialog';
|
||||
import { useApiStore } from '../../stores/api';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useProjectsStore } from '../../stores/projects';
|
||||
import { usePageStore } from '../../stores/page';
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
const { page } = storeToRefs(usePageStore());
|
||||
const { currentProjects } = storeToRefs(useProjectsStore());
|
||||
const projectUri = ref("");
|
||||
const subject = ref("");
|
||||
const details = ref("");
|
||||
const projectUri =
|
||||
page.value.template === 'project' ? ref(page.value.uri) : ref('');
|
||||
const subject = ref('');
|
||||
const details = ref('');
|
||||
const api = useApiStore();
|
||||
const isOpen = ref(true);
|
||||
const emits = defineEmits("close");
|
||||
const emits = defineEmits('close');
|
||||
|
||||
watch(isOpen, (newValue) => {
|
||||
if (!newValue) {
|
||||
emits("close");
|
||||
emits('close');
|
||||
}
|
||||
});
|
||||
|
||||
function preventClose(event) {
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
const formData = {
|
||||
projectUri: projectUri.value,
|
||||
|
|
@ -103,7 +112,7 @@ async function handleSubmit() {
|
|||
|
||||
const response = await api.post(
|
||||
formData,
|
||||
"/request-optimization-appointment.json"
|
||||
'/request-optimization-appointment.json'
|
||||
);
|
||||
isOpen.value = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,15 +21,22 @@
|
|||
class="order-last | text-sm text-primary font-medium"
|
||||
>
|
||||
{{ images[0].comments.length }} commentaire{{
|
||||
images[0].comments.length > 1 ? "s" : ""
|
||||
images[0].comments.length > 1 ? 's' : ''
|
||||
}}
|
||||
</footer>
|
||||
<div class="btn btn--xs btn--dtl | mt-16" v-if="isDesignToLightStep(step)" data-icon="leaf" lang="en">Design to Light</div>
|
||||
<div
|
||||
class="btn btn--xs btn--dtl | mt-16"
|
||||
v-if="isDesignToLightStep(step)"
|
||||
data-icon="leaf"
|
||||
lang="en"
|
||||
>
|
||||
Design to Light
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
<script setup>
|
||||
import DateTime from "./DateTime.vue";
|
||||
import { useDesignToLightStore } from "../../../stores/designToLight";
|
||||
import DateTime from './DateTime.vue';
|
||||
import { useDesignToLightStore } from '../../../stores/designToLight';
|
||||
|
||||
const { images, step, uri } = defineProps({
|
||||
images: Array,
|
||||
|
|
|
|||
|
|
@ -7,31 +7,39 @@
|
|||
/>
|
||||
</template>
|
||||
<script setup>
|
||||
import Images from "./Images.vue";
|
||||
import { computed } from "vue";
|
||||
import Images from './Images.vue';
|
||||
import { computed } from 'vue';
|
||||
const { step } = defineProps({ step: Object });
|
||||
|
||||
const images = computed(() => {
|
||||
if (!step.files.dynamic) {
|
||||
return [
|
||||
{
|
||||
url: step.files.static.rawGlass.cover,
|
||||
url: step.files?.static?.rawGlass?.cover,
|
||||
},
|
||||
{
|
||||
url: step.files?.static?.finishedGlass?.cover,
|
||||
},
|
||||
];
|
||||
}
|
||||
return step.files?.dynamic?.map((track) => getFrontView(track)) ?? [];
|
||||
|
||||
return (
|
||||
step.files?.dynamic?.map(
|
||||
(track) => (getFrontView(track)['dynamic'] = true)
|
||||
) ?? []
|
||||
);
|
||||
});
|
||||
|
||||
const uri = "/" + step.uri;
|
||||
const uri = '/' + step.uri;
|
||||
|
||||
function getFrontView(track) {
|
||||
if (track.files.length === 1) return track.files[0];
|
||||
const xMax = parseInt(
|
||||
track.files[track.files.length - 1].name.split("_")[1].split(".")[0]
|
||||
track.files[track.files.length - 1].name.split('_')[1].split('.')[0]
|
||||
);
|
||||
const xFrontView = (xMax + 1) / 2;
|
||||
const extension = track.files[0].name.split(".")[1];
|
||||
const frontViewName = "0_" + xFrontView + "." + extension;
|
||||
const extension = track.files[0].name.split('.')[1];
|
||||
const frontViewName = '0_' + xFrontView + '.' + extension;
|
||||
const frontView = track.files.find((file) => file.name === frontViewName);
|
||||
return frontView;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,11 +68,11 @@
|
|||
/>
|
||||
</template>
|
||||
<script setup>
|
||||
import { storeToRefs } from "pinia";
|
||||
import { usePageStore } from "../stores/page";
|
||||
import OptimizationRequestDialog from "../components/design-to-light/OptimizationRequestDialog.vue";
|
||||
import ProjectRequestDialog from "../components/ProjectRequestDialog.vue";
|
||||
import { computed, ref } from "vue";
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { usePageStore } from '../stores/page';
|
||||
import OptimizationRequestDialog from '../components/design-to-light/OptimizationRequestDialog.vue';
|
||||
import ProjectRequestDialog from '../components/ProjectRequestDialog.vue';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
const { page } = storeToRefs(usePageStore());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue