Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import 'package:clean_stream_laundry_app/Logic/Theme/theme.dart';
import 'package:flutter/material.dart';
import 'package:app_links/app_links.dart';
import 'controller.dart';
import 'widgets/resend_verification.dart';

class ChangeEmailVerificationPage extends StatefulWidget {
final AppLinks appLinks;

const ChangeEmailVerificationPage({super.key, required this.appLinks});

@override
State<ChangeEmailVerificationPage> createState() =>
_ChangeEmailVerificationPageState();
}

class _ChangeEmailVerificationPageState
extends State<ChangeEmailVerificationPage> {
late final ChangeEmailVerificationController _controller;

@override
void initState() {
super.initState();
_controller = ChangeEmailVerificationController(
appLinks: widget.appLinks,
context: context,
);
_controller.init();
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

void _refresh() {
setState(() {});
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
body: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.email, size: 80, color: Colors.blueAccent),
const SizedBox(height: 24),
Text(
'Please verify your new email address',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
color: Theme.of(context).colorScheme.fontInverted,
),
),
const SizedBox(height: 16),
Text(
'Check your new email\'s inbox and click the verification link.',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
color: Theme.of(context).colorScheme.fontSecondary,
),
),
const SizedBox(height: 24),
ResendVerificationWidget(
controller: _controller,
onStateChange: _refresh,
),
],
),
),
),
);
}
}
60 changes: 60 additions & 0 deletions lib/features/change_email_verification/controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:clean_stream_laundry_app/logic/enums/authentication_response_enum.dart';
import 'package:clean_stream_laundry_app/logic/services/auth_service.dart';
import 'package:get_it/get_it.dart';
import 'package:go_router/go_router.dart';
import 'package:app_links/app_links.dart';

class ChangeEmailVerificationController {
final AuthService _authService = GetIt.instance<AuthService>();
final AppLinks appLinks;
final BuildContext context;

StreamSubscription? _linkSub;

bool resent = false;
bool isLoading = false;
AuthenticationResponses? lastResponse;

ChangeEmailVerificationController({
required this.appLinks,
required this.context,
});

void init() {
_linkSub = appLinks.uriLinkStream.listen(_handleUri);
}

void dispose() {
_linkSub?.cancel();
}

/// Handles deeplink from email
Future<void> _handleUri(Uri? uri) async {
if (uri != null &&
uri.scheme == 'clean-stream' &&
uri.host == 'change-email') {
await _authService.refreshSession();
await _authService.getCurrentUser();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (context.mounted) {
context.go('/editProfile');
}
});
}
}

/// Resends verification email
Future<void> resendVerification() async {
if (resent) return;

isLoading = true;
lastResponse = await _authService.resendVerification();
isLoading = false;

if (lastResponse == AuthenticationResponses.success) {
resent = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:flutter/material.dart';
import '../controller.dart';
import 'verification_error.dart';
import '../../../logic/enums/authentication_response_enum.dart';

class ResendVerificationWidget extends StatefulWidget {
final ChangeEmailVerificationController controller;
final VoidCallback onStateChange;

const ResendVerificationWidget({
super.key,
required this.controller,
required this.onStateChange,
});

@override
State<ResendVerificationWidget> createState() =>
_ResendVerificationWidgetState();
}

class _ResendVerificationWidgetState extends State<ResendVerificationWidget> {
@override
Widget build(BuildContext context) {
if (widget.controller.isLoading) {
return const CircularProgressIndicator();
}

if (widget.controller.resent) {
return const Icon(Icons.check_circle, size: 40, color: Colors.green);
}

return InkWell(
onTap: () async {
await widget.controller.resendVerification();
widget.onStateChange();
},
child: widget.controller.lastResponse == null
? const Text(
'Resend Verification',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.blue, decoration: TextDecoration.underline),
)
: widget.controller.lastResponse == AuthenticationResponses.failure
? const VerificationError()
: const SizedBox.shrink(),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:clean_stream_laundry_app/Logic/Theme/theme.dart';
import 'package:flutter/material.dart';

class VerificationError extends StatelessWidget {
const VerificationError({super.key});

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 80,
height: 80,
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
child: const Center(
child: Icon(Icons.close, color: Colors.white, size: 40),
),
),
const SizedBox(height: 16),
Text(
'Please resend verification again at another time.',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
color: Theme.of(context).colorScheme.fontPrimary,
),
),
],
);
}
}
2 changes: 1 addition & 1 deletion supabase/functions/checkPaymentResult/logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Deno.test("throws if sessionId is missing", async () => {
retrieveSession: async (id) => ({ payment_status: "paid" }),
};

await assertRejects( // await + assertRejects
await assertRejects(
() => getPaymentStatusLogic({ sessionId: "" }, fakeDeps),
Error,
"Missing sessionId"
Expand Down
5 changes: 1 addition & 4 deletions supabase/functions/denyRefund/logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import {
}

function restoreFetch() {
// Deno's real fetch is on globalThis — reset after each test
globalThis.fetch = fetch;
}

Expand Down Expand Up @@ -119,7 +118,6 @@ import {

Deno.test("denyRefundInDb — resolves without error on success", async () => {
const supabase = makeSupabaseMock();
// should not throw
await denyRefundInDb(supabase, "txn-abc");
});

Expand Down Expand Up @@ -178,7 +176,7 @@ import {
});

Deno.test("getUserEmail — throws when user has no email", async () => {
const supabase = makeSupabaseMock({ user: { id: "user-123" } }); // no email field
const supabase = makeSupabaseMock({ user: { id: "user-123" } });

await assertRejects(
() => getUserEmail(supabase, "user-123"),
Expand Down Expand Up @@ -276,7 +274,6 @@ import {
} finally {
restoreFetch();
}
// reaching here without throwing is the assertion
});

Deno.test("sendDenialEmail — throws with error text when response is not ok", async () => {
Expand Down
Loading
Loading