All files / src/routes/onboarding +page.svelte

0% Statements 0/22
0% Branches 0/2
0% Functions 0/6
0% Lines 0/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
<script lang="ts">
	import { enhance } from '$app/forms';
	import Button from '$lib/components/Button.svelte';
	import Card from '$lib/components/Card.svelte';
	import OptionCard from '$lib/components/OptionCard.svelte';
	import PageHeader from '$lib/components/PageHeader.svelte';
 
	const experienceOptions = [
		{ value: 'beginner', label: 'Beginner', description: 'New to structured training' },
		{ value: 'intermediate', label: 'Intermediate', description: 'Comfortable with the basics' },
		{ value: 'advanced', label: 'Advanced', description: 'Years of consistent training' },
	] as const;
 
	const parqQuestions = [
		{ name: 'has_heart_condition', label: 'Do you have a heart condition?' },
		{ name: 'has_chest_pain', label: 'Do you experience chest pain during physical activity?' },
		{ name: 'has_dizziness', label: 'Do you experience dizziness or loss of balance?' },
		{
			name: 'has_bone_joint_problem',
			label: 'Do you have a bone or joint problem that could be worsened by exercise?',
		},
		{
			name: 'has_blood_pressure_medication',
			label: 'Are you currently taking blood pressure medication?',
		},
		{
			name: 'other_physical_reason',
			label: 'Is there any other physical reason you should not exercise?',
		},
	] as const;
 
	let responses = $state(
		Object.fromEntries(parqQuestions.map((q) => [q.name, false])) as Record<string, boolean>,
	);
 
	let experienceLevel = $state('');
 
	let IanyFlagged = $derived(Object.values(responses).some(Boolean));
 
	let form: { error?: string } | null = $state(null);
</script>
 
<svelte:head>
	<title>Health Screening | Strengthsys</title>
</svelte:head>
 
<section class="onboarding">
	<div class="onboarding__head">
		<PageHeader
			eyebrow="Step 1 of 2"
			lede="A couple of quick questions so we can train you safely. Nothing here is shared — it just shapes what we suggest."
		>
			Health <em>Screening</em>
		</PageHeader>
	</div>
 
	<form
		method="POST"
		use:enhance={() => {
			return async ({ result, update }) => {
				if (result.type === 'failure') {
					form = result.data as { error?: string };
				} else {
					await update();
				}
			};
		}}
	>
		<Card>
			<fieldset class="parq">
				<legend class="parq__legend">Physical Activity Readiness</legend>
 
				<div class="parq__list">
					{#each parqQuestions as question (question.name)}
						<div class="parq__row" data-testid="parq-{question.name}">
							<p class="parq__question">{question.label}</p>
							<div class="parq__options">
								<!--
									OptionCard (Coastal v2) replaces the native Yes/No radios. The
									value still rides to the server through a hidden input carrying the
									same field name, so the FormData contract (formData.get(name) ===
									'true') is unchanged. Default "No" selected mirrors the prior
									default-false responses map.
								-->
								<OptionCard
									label="Yes"
									aria-label="{question.label} — Yes"
									selected={responses[question.name] === true}
									onclick={() => (responses[question.name] = true)}
								/>
								<OptionCard
									label="No"
									aria-label="{question.label} — No"
									selected={responses[question.name] === false}
									onclick={() => (responses[question.name] = false)}
								/>
							</div>
							<input type="hidden" name={question.name} value={String(responses[question.name])} />
						</div>
					{/each}
				</div>
			</fieldset>
		</Card>
 
		{#if anyFlagged}
			<div role="alert" class="parq__advisory">
				<Card tone="coral" class="parq__advisory-card">
					<p>
						<strong>Important:</strong> Based on your responses, we recommend consulting a
						physician before beginning an exercise programme. You may still continue, but please
						consider seeking professional medical advice.
					</p>
				</Card>
			</div>
		{/if}
 
		<Card>
			<fieldset class="experience">
				<legend class="experience__legend">Experience Level</legend>
 
				<div class="experience__options">
					{#each experienceOptions as option (option.value)}
						<OptionCard
							label={option.label}
							description={option.description}
							selected={experienceLevel === option.value}
							onclick={() => (experienceLevel = option.value)}
						/>
					{/each}
				</div>
				<input type="hidden" name="experience_level" value={experienceLevel} />
			</fieldset>
		</Card>
 
		{#if Iform?.error}
			<p class="onboarding__error" role="alert">{form.error}</p>
		{/if}
 
		<div class="onboarding__actions">
			<Button type="submit" size="lg" disabled={!experienceLevel}>Continue</Button>
		</div>
	</form>
</section>
 
<style>
	.onboarding {
		display: flex;
		flex-direction: column;
		gap: var(--space-6);
		padding: var(--space-5) 0 var(--space-9);
	}
 
	.onboarding__head :global(.page-header) {
		align-items: center;
		text-align: center;
	}
 
	form {
		display: flex;
		flex-direction: column;
		gap: var(--space-5);
	}
 
	.parq__legend,
	.experience__legend {
		font-family: var(--font-sans);
		font-size: 14px;
		font-weight: 600;
		color: var(--ink);
		margin-bottom: var(--space-4);
		padding: 0;
	}
 
	.parq__list {
		display: flex;
		flex-direction: column;
		gap: var(--space-4);
	}
 
	.parq__row {
		display: flex;
		flex-direction: column;
		gap: var(--space-2);
		padding-bottom: var(--space-4);
		border-bottom: 1px solid var(--line);
	}
 
	.parq__row:last-child {
		padding-bottom: 0;
		border-bottom: 0;
	}
 
	.parq__question {
		margin: 0;
		font-size: 15px;
		color: var(--ink);
		line-height: 1.4;
	}
 
	/* Yes/No OptionCards, two-up. Falls back to a single column on the
	   narrowest screens so the tap targets never crowd. */
	.parq__options {
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: var(--space-3);
	}
 
	.experience__options {
		display: grid;
		grid-template-columns: repeat(3, 1fr);
		gap: var(--space-3);
	}
 
	@media (max-width: 600px) {
		.experience__options {
			grid-template-columns: 1fr;
		}
	}
 
	:global(.parq__advisory-card) {
		border-left: 4px solid var(--coral);
	}
 
	:global(.parq__advisory-card p) {
		margin: 0;
		color: var(--on-coral-soft);
		line-height: 1.5;
	}
 
	.onboarding__error {
		margin: 0;
		font-size: 14px;
		color: var(--danger);
	}
 
	.onboarding__actions {
		display: flex;
		justify-content: flex-end;
	}
 
	@media (max-width: 600px) {
		.onboarding__actions {
			justify-content: stretch;
		}
 
		.onboarding__actions :global(.btn) {
			width: 100%;
		}
	}
</style>