From 37e14af951ec73a35a7ae98889091daf42b48704 Mon Sep 17 00:00:00 2001 From: Clark Sell Date: Fri, 15 Sep 2023 17:27:13 -0500 Subject: [PATCH] fix: shared profile --- running-backlog.md | 1 - .../api.that.tech/me/mutations.js | 5 +- .../my/profiles/shared/+page.server.js | 28 ++- .../my/profiles/shared/+page.svelte | 17 +- .../profiles/shared/sharedProfileForm.svelte | 171 +++++++++++------- 5 files changed, 132 insertions(+), 90 deletions(-) diff --git a/running-backlog.md b/running-backlog.md index 24ca4da..20b8814 100644 --- a/running-backlog.md +++ b/running-backlog.md @@ -1,6 +1,5 @@ # Migration to thatconference.com -- Validate Slug - fix other profiles - forms lib upgraded - event hero image diff --git a/src/_dataSources/api.that.tech/me/mutations.js b/src/_dataSources/api.that.tech/me/mutations.js index af104cb..0dd5f78 100644 --- a/src/_dataSources/api.that.tech/me/mutations.js +++ b/src/_dataSources/api.that.tech/me/mutations.js @@ -32,7 +32,10 @@ export default (fetch) => { return client .mutation({ mutation: MUTATION_UPDATE_SHARED_PROFILE, variables }) .then(({ data, errors }) => { - if (errors) log({ errors, tag: 'MUTATION_CHECK_IN_USER' }); + if (errors) { + log({ errors, tag: 'MUTATION_CHECK_IN_USER' }); + throw new Error('An error occurred while updating your shared profile.'); + } let results; diff --git a/src/routes/(admin my)/my/profiles/shared/+page.server.js b/src/routes/(admin my)/my/profiles/shared/+page.server.js index 927e03a..e555d0b 100644 --- a/src/routes/(admin my)/my/profiles/shared/+page.server.js +++ b/src/routes/(admin my)/my/profiles/shared/+page.server.js @@ -1,7 +1,9 @@ import { fail } from '@sveltejs/kit'; import { superValidate } from 'sveltekit-superforms/server'; +import { redirect, setFlash } from 'sveltekit-flash-message/server'; import meQueryApi from '$dataSources/api.that.tech/me/queries'; +import meMutationsApi from '$dataSources/api.that.tech/me/mutations'; import sharedProfileSchema from '$lib/formSchemas/sharedProfile'; export async function load({ fetch }) { @@ -17,9 +19,10 @@ export async function load({ fetch }) { } export const actions = { - default: async ({ request }) => { - const form = await superValidate(request, sharedProfileSchema); - console.log('POST', form); + default: async (event) => { + const { updateSharedProfile } = meMutationsApi(event.fetch); + + const form = await superValidate(event, sharedProfileSchema); if (!form.valid) { return fail(400, { @@ -27,6 +30,23 @@ export const actions = { }); } - return { form }; + try { + await updateSharedProfile(form.data); + + const successMessage = { + type: 'success', + message: `Your shared profile contact information has been updated.` + }; + + setFlash(successMessage, event); + return { form }; + } catch (error) { + const errorMessage = { + type: 'error', + message: `Whoops!!! ${error.message}` + }; + + throw redirect(errorMessage, event); + } } }; diff --git a/src/routes/(admin my)/my/profiles/shared/+page.svelte b/src/routes/(admin my)/my/profiles/shared/+page.svelte index cd6f2f9..a4c0c98 100644 --- a/src/routes/(admin my)/my/profiles/shared/+page.svelte +++ b/src/routes/(admin my)/my/profiles/shared/+page.svelte @@ -9,23 +9,8 @@ import { Warning } from '$elements/svgs'; import SharedProfileForm from './sharedProfileForm.svelte'; - // import meMutationsApi from '$dataSources/api.that.tech/me/mutations'; const { isEmpty } = lodash; - // const { updateSharedProfile } = meMutationsApi(); - - // async function handleUpdate({ detail: { values, setSubmitting } }) { - // setSubmitting(true); - - // try { - // await updateSharedProfile(values); - // } catch (e) { - // //todo what do we do here? - // console.error(e); - // } - - // setSubmitting(false); - // } const metaTags = ((title = 'My Shared Profile - THAT') => ({ title, @@ -34,7 +19,7 @@ description: 'Create or update your shared THAT profile.', openGraph: { type: 'website', - url: `https://that.us/my/profiles/shared/` + url: `https://thatconference.com/my/profiles/shared/` }, nofollow: true, noindex: true diff --git a/src/routes/(admin my)/my/profiles/shared/sharedProfileForm.svelte b/src/routes/(admin my)/my/profiles/shared/sharedProfileForm.svelte index 5c1fe34..393851e 100644 --- a/src/routes/(admin my)/my/profiles/shared/sharedProfileForm.svelte +++ b/src/routes/(admin my)/my/profiles/shared/sharedProfileForm.svelte @@ -4,18 +4,16 @@ import { getContext } from 'svelte'; import { superForm } from 'sveltekit-superforms/client'; - import SuperDebug from 'sveltekit-superforms/client/SuperDebug.svelte'; import * as flashModule from 'sveltekit-flash-message/client'; + import { AlertOctagon } from 'lucide-svelte'; import Select from 'svelte-select'; - import { Shell } from '$elements/buttons'; + import { DisabledShell, Shell } from '$elements/buttons'; import sharedProfileFormSchema from '$lib/formSchemas/sharedProfile'; const { countryCode } = getContext('DROP_DOWN_KEY_VALUE_PAIRS'); - let countryCodeValue = countryCode?.options?.find(({ value }) => value === sForm.country); - - const { form, enhance, constraints } = superForm(sForm, { + const { form, enhance, constraints, errors, allErrors } = superForm(sForm, { dataType: 'json', validators: sharedProfileFormSchema, syncFlashMessage: false, @@ -25,6 +23,7 @@ } }); + let countryCodeSelect = countryCode?.options?.find(({ value }) => value === $form.country); let formattedPhoneNumber = ''; function formatPhoneNumber(event) { // Remove all non-numeric characters from the input @@ -82,14 +81,16 @@ -
- -
+ + + {#if $errors.firstName} + {$errors.firstName} + {/if}
@@ -100,13 +101,16 @@
-
- -
+ + + + {#if $errors.lastName} + {$errors.lastName} + {/if}
@@ -117,14 +121,16 @@
-
- -
+ + + {#if $errors.email} + {$errors.email} + {/if}
@@ -138,42 +144,53 @@
-
- -
+ + + + {#if $errors.city} + {$errors.city} + {/if}
-
- -
+ + + + {#if $errors.state} + {$errors.state} + {/if}
-
+ +
-
+ + + + {#if $errors.company} + {$errors.company} + {/if}
-
-
-
- - - +
+ {#if $allErrors.length} +
+ {#each $allErrors as error} +
+ +

{error.messages}

+
+ {/each}
+ {/if} + +
+ {#if $allErrors.length > 0} + +
Save Profile
+
+ {:else} + + {/if}
- -
- -