2026-04-21 14:35:13 +00:00
|
|
|
<template>
|
2026-04-21 14:45:11 +00:00
|
|
|
<PublicReportLoading />
|
2026-04-21 14:35:13 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-04-21 14:45:11 +00:00
|
|
|
import { onMounted } from "vue";
|
2026-04-21 14:35:13 +00:00
|
|
|
import { useRouter } from "vue-router";
|
|
|
|
|
|
|
|
|
|
import { useStoreDistrict } from "@/rmo/store/district";
|
|
|
|
|
import { useStoreLocal } from "@/store/local";
|
2026-04-29 22:36:33 +00:00
|
|
|
import { useStorePublicReport } from "@/rmo/store/publicreport";
|
2026-04-21 14:45:11 +00:00
|
|
|
import PublicReportLoading from "@/rmo/components/PublicReportLoading.vue";
|
|
|
|
|
import { type District } from "@/type/api";
|
2026-04-21 14:35:13 +00:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
slug: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const districtStore = useStoreDistrict();
|
|
|
|
|
|
|
|
|
|
const props = defineProps<Props>();
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const storeLocal = useStoreLocal();
|
|
|
|
|
const storePublicReport = useStorePublicReport();
|
|
|
|
|
async function doMounted() {
|
|
|
|
|
const client_id = storeLocal.getClientID();
|
|
|
|
|
const report_uri = storeLocal.getExistingComplianceReportURI();
|
|
|
|
|
if (report_uri) {
|
|
|
|
|
const report = await storePublicReport.byURI(report_uri);
|
|
|
|
|
if (report && report.public_id) {
|
|
|
|
|
router.replace(`/compliance/${report.public_id}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const districts = await districtStore.list();
|
|
|
|
|
const district = districts.find(
|
|
|
|
|
(district: District) => district.slug == props.slug,
|
|
|
|
|
);
|
|
|
|
|
if (!district) {
|
|
|
|
|
console.error("failed to find matching district", props.slug, districts);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-04-21 14:41:06 +00:00
|
|
|
const report = await storePublicReport.createCompliance({
|
2026-04-21 14:35:13 +00:00
|
|
|
client_id: client_id,
|
|
|
|
|
district: district.uri,
|
|
|
|
|
});
|
|
|
|
|
storeLocal.setExistingComplianceReportURI(report.uri);
|
|
|
|
|
router.replace(`/compliance/${report.public_id}`);
|
2026-04-21 14:41:06 +00:00
|
|
|
console.log("Created new compliance report", report);
|
2026-04-21 14:35:13 +00:00
|
|
|
}
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
doMounted();
|
|
|
|
|
});
|
|
|
|
|
</script>
|