From 6196e20f1d1ab0d0feed4ce983e3073f14f9eef4 Mon Sep 17 00:00:00 2001 From: novellac <38117965+novellac@users.noreply.github.com> Date: Sat, 22 Apr 2023 14:40:02 -0400 Subject: [PATCH] feat: Add alerts and reminder notification (#8) * feat: Notification component with status and alert * feat: Add reminders and error messages --- src/App.vue | 131 ++++++++++++++++----- src/components/BaseNotification.stories.js | 48 ++++++++ src/components/BaseNotification.vue | 35 ++++++ src/components/StepInput.vue | 17 ++- 4 files changed, 200 insertions(+), 31 deletions(-) create mode 100644 src/components/BaseNotification.stories.js create mode 100644 src/components/BaseNotification.vue diff --git a/src/App.vue b/src/App.vue index 3314f74..881f1a9 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,30 +5,60 @@ - -
- - - - - - - - - -
+ + + + + Please fill in the missing information so we can keep things cookin'! + + + +
+ +
+ + + + + + + + + +
+
-

- Your generated pitches -

+ +
+

Your generated pitches

+ + + + + + +
-
    import { inject } from '@vercel/analytics' -import { onMounted, ref } from 'vue' +import { computed, nextTick, onMounted, reactive, ref } from 'vue' import TheHeader from './components/TheHeader.vue' import BaseButton from './components/BaseButton.vue' +import BaseNotification from './components/BaseNotification.vue' import StepInput from './components/StepInput.vue' import ResultCardLoading from './components/ResultCardLoading.vue' import ResultCard from './components/ResultCard.vue' -const jobDescription = ref( - 'Ex: A talented vegan chef who likes cooking desserts and has 78 years of experience.' -) -const bio = ref('Ex: A chef with 6 years of experience in cooking steaks.') +const jobDescription = ref('') +const bio = ref('') const results = ref([]) const isLoading = ref(false) +const hasAnyErrors = computed(() => { + return Object.values(errors).some((item) => item === true) +}) + +const errors = reactive({ + jobDescription: false, + bio: false, +}) + +const calculateErrors = async () => { + // Reset errors so we can recalculate, since users may have since changed input values. + resetErrors() + + // Let DOM update so assistive tech will be re-triggered. + await nextTick() + + if (!bio.value) errors.bio = true + if (!jobDescription.value) errors.jobDescription = true +} + +const resetErrors = () => { + Object.keys(errors).forEach((field) => { + errors[field] = false + }) +} + const getCompletion = async () => { + // Use may have double clicked if (isLoading.value) return + await calculateErrors() + if (hasAnyErrors.value) return + isLoading.value = true const response = await fetch('/api/generate', { diff --git a/src/components/BaseNotification.stories.js b/src/components/BaseNotification.stories.js new file mode 100644 index 0000000..812504a --- /dev/null +++ b/src/components/BaseNotification.stories.js @@ -0,0 +1,48 @@ +import BaseNotification from './BaseNotification.vue' + +export default { + title: 'Notifications', + component: BaseNotification, +} + +const StatusTemplate = (args) => ({ + components: { BaseNotification }, + setup() { + return { args } + }, + template: ` + + + + In order to get the most out of this app, please adjust your phasers to stun and hold on tight to the handrails. + + `, +}) + +export const Status = StatusTemplate.bind({}) +Status.args = { + role: 'status', +} + +const AlertTemplate = (args) => ({ + components: { BaseNotification }, + setup() { + return { args } + }, + template: ` + + + + Please do brush your unicorn a little more thorougly, so that your unicorn will keep that glossy mane and coat we've come to know and love. + + `, +}) + +export const Alert = AlertTemplate.bind({}) +Alert.args = { + role: 'alert', +} diff --git a/src/components/BaseNotification.vue b/src/components/BaseNotification.vue new file mode 100644 index 0000000..4c56106 --- /dev/null +++ b/src/components/BaseNotification.vue @@ -0,0 +1,35 @@ + + + diff --git a/src/components/StepInput.vue b/src/components/StepInput.vue index 573a806..c0fe0c8 100644 --- a/src/components/StepInput.vue +++ b/src/components/StepInput.vue @@ -3,7 +3,12 @@ import BaseLabel from './BaseLabel.vue';