Skip to content

Commit

Permalink
Merge branch 'main' into prod/festapp
Browse files Browse the repository at this point in the history
  • Loading branch information
miakh committed Nov 11, 2024
2 parents b3cd8fc + 8fe8ff9 commit e749927
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 34 deletions.
2 changes: 1 addition & 1 deletion assets/translations/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
"Food": "Jídlo",
"To create food, fill in the title, unique code, and the reference of the event.": "Pro vytvoření jídla vyplňte název, jedinečný kód a referenci na program.",
"Not specified": "Nespecifikováno",
"Users will get a sign in code via e-mail.": "Uživatelé obdrží přihlašovací kód e-mailem.",
"Users will get a sign-in code via e-mail.": "Uživatelé obdrží přihlašovací kód e-mailem.",
"Users ({count}) invited successfully.": "Uživatelé ({count}) byli úspěšně pozváni.",
"Progress": "Postup",
"_": "_"
Expand Down
2 changes: 1 addition & 1 deletion assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
"Food": "Essen",
"To create food, fill in the title, unique code, and the reference of the event.": "Um Essen zu erstellen, füllen Sie den Titel, den eindeutigen Code und die Referenz des Programms aus.",
"Not specified": "Nicht angegeben",
"Users will get a sign in code via e-mail.": "Benutzer erhalten einen Anmeldecode per E-Mail.",
"Users will get a sign-in code via e-mail.": "Benutzer erhalten einen Anmeldecode per E-Mail.",
"Users ({count}) invited successfully.": "Benutzer ({count}) wurden erfolgreich eingeladen.",
"Progress": "Fortschritt",
"_": "_"
Expand Down
3 changes: 2 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@
"Food": "Food",
"To create food, fill in the title, unique code, and the reference of the event.": "To create food, fill in the title, unique code, and the reference of the event.",
"Not specified": "Not specified",
"Users will get a sign in code via e-mail.": "Users will get a sign in code via e-mail.",
"Users will get a sign-in code via e-mail.": "Users will get a sign-in code via e-mail.",
"Users ({count}) invited successfully.": "Users ({count}) invited successfully.",
"Progress": "Progress",
"Some users have already been invited. Do you want to invite them again and send a new sign-in code?": "Some users have already been invited. Do you want to invite them again and send a new sign-in code?",
"_":"_"
}
2 changes: 1 addition & 1 deletion assets/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
"Food": "Jedzenie",
"To create food, fill in the title, unique code, and the reference of the event.": "Aby utworzyć jedzenie, wypełnij tytuł, unikalny kod i odniesienie do programu.",
"Not specified": "Nieokreślony",
"Users will get a sign in code via e-mail.": "Użytkownicy otrzymają kod logowania za pomocą e-maila.",
"Users will get a sign-in code via e-mail.": "Użytkownicy otrzymają kod logowania za pomocą e-maila.",
"Users ({count}) invited successfully.": "Użytkownicy ({count}) zostali pomyślnie zaproszeni.",
"Progress": "Postęp",
"_": "_"
Expand Down
2 changes: 1 addition & 1 deletion assets/translations/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
"Food": "Jedlo",
"To create food, fill in the title, unique code, and the reference of the event.": "Na vytvorenie jedla vyplňte názov, jedinečný kód a referenciu na program.",
"Not specified": "Neurčené",
"Users will get a sign in code via e-mail.": "Používatelia dostanú prihlasovací kód e-mailom.",
"Users will get a sign-in code via e-mail.": "Používatelia dostanú prihlasovací kód e-mailom.",
"Users ({count}) invited successfully.": "Používatelia ({count}) boli úspešne pozvaní.",
"Progress": "Postup",
"_": "_"
Expand Down
2 changes: 1 addition & 1 deletion assets/translations/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
"Food": "Їжа",
"To create food, fill in the title, unique code, and the reference of the event.": "Щоб створити їжу, заповніть назву, унікальний код та посилання на програму.",
"Not specified": "Не вказано",
"Users will get a sign in code via e-mail.": "Користувачі отримають код для входу на електронну пошту.",
"Users will get a sign-in code via e-mail.": "Користувачі отримають код для входу на електронну пошту.",
"Users ({count}) invited successfully.": "Користувачі ({count}) успішно запрошені.",
"Progress": "Прогрес",
"_": "_"
Expand Down
2 changes: 1 addition & 1 deletion lib/AppRouter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AppRouter extends RootStackRouter {
]),
AutoRoute(page: NewsRoute.page, path: "${NewsPage.ROUTE}"),
AutoRoute(page: SongRoute.page, path: "${SongPage.ROUTE}"),
AutoRoute(page: MapRoute.page, path: "${MapPage.ROUTE}", children: [
AutoRoute(page: MapRoute.page, path: "${MapPage.ROUTE}", maintainState: false, children: [
AutoRoute(path: ':id', page: MapRoute.page,),
]),
AutoRoute(page: InfoRoute.page, path: "${InfoPage.ROUTE}", children: [
Expand Down
45 changes: 31 additions & 14 deletions lib/pages/AdministrationOccasion/UsersTab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ class _UsersTabState extends State<UsersTab> {
await loadUsers(); // Reload users and force rebuild
}

Future<void> _invite(SingleTableDataGrid dataGrid) async {
var users = _getCheckedUsers(dataGrid);
if (users.isEmpty) return;
await _processInvites(users, dataGrid);
}

Future<void> _setPassword(SingleTableDataGrid dataGrid) async {
var users = _getCheckedUsers(dataGrid);
if (users.isEmpty) return;
Expand Down Expand Up @@ -132,17 +126,44 @@ class _UsersTabState extends State<UsersTab> {
);
}

Future<void> _invite(SingleTableDataGrid dataGrid) async {
var users = _getCheckedUsers(dataGrid);
if (users.isEmpty) return;

// Separate already invited users
var alreadyInvitedUsers = users.where((user) => user.data![Tb.occasion_users.data_isInvited] == true).toList();
var newUsers = users.where((user) => user.data![Tb.occasion_users.data_isInvited] != true).toList();

if (alreadyInvitedUsers.isNotEmpty) {
// Ask the user if they want to reinvite already invited users
var reinviteConfirm = await DialogHelper.showConfirmationDialogAsync(
context,
"Invite".tr(),
"Some users have already been invited. Do you want to invite them again and send a new sign-in code?".tr(),
);

// If the user chooses not to reinvite, exclude already invited users
if (!reinviteConfirm) {
await _processInvites(newUsers, dataGrid);
return;
}
}

// Proceed with inviting both new and previously invited users (if reinvite confirmed)
await _processInvites(users, dataGrid);
}

Future<void> _processInvites(List<OccasionUserModel> users, SingleTableDataGrid dataGrid) async {
var confirm = await DialogHelper.showConfirmationDialogAsync(
context,
"Invite".tr(),
"${"Users will get a sign in code invitation via e-mail.".tr()} (${users.length}):\n${users.map((u) => u.toBasicString()).join(",\n")}"
"${"Users will get a sign-in code via e-mail.".tr()} (${users.length}):\n${users.map((u) => u.toBasicString()).join(",\n")}"
);

if (confirm) {
ValueNotifier<int> invitedCount = ValueNotifier(0);

// Show the progress dialog and update the count via the notifier
// Show progress dialog
DialogHelper.showProgressDialogAsync(
context,
"Invite".tr(),
Expand All @@ -154,25 +175,21 @@ class _UsersTabState extends State<UsersTab> {
await AuthService.sendSignInCode(user);
invitedCount.value++;

// Show toast notification after each invitation
ToastHelper.Show(
context,
"Invited: {user}.".tr(namedArgs: {"user": user.data![Tb.occasion_users.data_email]}),
);
}

// Close the dialog after all users are invited
Navigator.of(context).pop();
Navigator.of(context).pop(); // Close the dialog

await loadUsers(); // Reload users and force rebuild
await loadUsers(); // Reload users

// Display final information dialog
await DialogHelper.showInformationDialogAsync(
context,
"Invite".tr(),
"Users ({count}) invited successfully.".tr(namedArgs: {"count": invitedCount.value.toString()}),
);

}
}
}
14 changes: 7 additions & 7 deletions supabase/functions/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sendEmailWithSubs } from "../_shared/emailClient.ts";
import { createClient } from 'https://esm.sh/@supabase/[email protected]';

const _DEFAULT_EMAIL = Deno.env.get("DEFAULT_EMAIL")!;
const _supabase = createClient(
const supabaseAdmin = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
);
Expand All @@ -21,7 +21,7 @@ Deno.serve(async (req) => {
const userEmail = reqData.email ? reqData.email.toLowerCase() : "[email protected]";
const organization = reqData.organization;

const orgData = await _supabase
const orgData = await supabaseAdmin
.from("organizations")
.select("data")
.eq("id", organization)
Expand All @@ -39,7 +39,7 @@ Deno.serve(async (req) => {
const appName = orgConfig.APP_NAME || "DefaultAppName";
const defaultUrl = orgConfig.DEFAULT_URL || "http://default.url";

const userData = await _supabase
const userData = await supabaseAdmin
.from("user_info")
.select()
.eq("organization", organization)
Expand All @@ -56,19 +56,19 @@ Deno.serve(async (req) => {
const userId = userData.data.id;
const token = crypto.randomUUID();

await _supabase
await supabaseAdmin
.from("user_reset_token")
.delete()
.eq("user", userId);

await _supabase
await supabaseAdmin
.from("user_reset_token")
.insert({
"user": userId,
"token": token,
});

const template = await _supabase
const template = await supabaseAdmin
.from("email_templates")
.select()
.eq("id", "RESET_PASSWORD")
Expand Down Expand Up @@ -96,7 +96,7 @@ Deno.serve(async (req) => {
from: `${appName} | Festapp <${_DEFAULT_EMAIL}>`,
});

await _supabase
await supabaseAdmin
.from("log_emails")
.insert({
"from": _DEFAULT_EMAIL,
Expand Down
12 changes: 6 additions & 6 deletions supabase/functions/register/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createClient } from 'https://esm.sh/@supabase/[email protected]';

const _DEFAULT_EMAIL = Deno.env.get("DEFAULT_EMAIL")!;

const _supabase = createClient(
const supabaseAdmin = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
);
Expand All @@ -22,7 +22,7 @@ Deno.serve(async (req) => {
const userEmail = reqData.email.trim();
const organizationId = reqData.organization;

const orgData = await _supabase
const orgData = await supabaseAdmin
.from("organizations")
.select("data")
.eq("id", organizationId)
Expand Down Expand Up @@ -51,7 +51,7 @@ Deno.serve(async (req) => {
);
}

const userData = await _supabase
const userData = await supabaseAdmin
.from("user_info")
.select()
.eq("email_readonly", userEmail)
Expand All @@ -67,14 +67,14 @@ Deno.serve(async (req) => {

const code = Math.floor(100000 + Math.random() * 900000).toString();

const { data } = await _supabase.rpc("create_user_in_organization_with_data", {
const { data } = await supabaseAdmin.rpc("create_user_in_organization_with_data", {
org: organizationId,
email: userEmail,
password: code,
data: reqData,
});

const template = await _supabase
const template = await supabaseAdmin
.from("email_templates")
.select()
.eq("id", "SIGN_IN_CODE")
Expand All @@ -93,7 +93,7 @@ Deno.serve(async (req) => {
from: `${appName} | Festapp <${_DEFAULT_EMAIL}>`,
});

await _supabase
await supabaseAdmin
.from("log_emails")
.insert({
"from": _DEFAULT_EMAIL,
Expand Down
14 changes: 14 additions & 0 deletions supabase/functions/send-sign-in-code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const corsHeaders = {
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
};

const supabaseAdmin = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
);

Deno.serve(async (req) => {
try {
if (req.method === 'OPTIONS') {
Expand Down Expand Up @@ -102,6 +107,15 @@ Deno.serve(async (req) => {
from: `Festapp <${_DEFAULT_EMAIL}>`,
});

await supabaseAdmin
.from("log_emails")
.insert({
"from": _DEFAULT_EMAIL,
"to": occasionUser.data.data.email,
"template": template.data.id,
"organization": organizationId
});

occasionUser.data.data.is_invited = true;
const { error: updateError } = await supabase
.from("occasion_users")
Expand Down

0 comments on commit e749927

Please sign in to comment.