Skip to content

Commit

Permalink
Notification now includes project name
Browse files Browse the repository at this point in the history
Also moved backend mutation back to using project ID now that it's easy
  • Loading branch information
rmunn committed Aug 5, 2024
1 parent b18077b commit 5bf54e2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
8 changes: 4 additions & 4 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ await dbContext.ProjectUsers
public async Task<IQueryable<Project>> AskToJoinProject(
IPermissionService permissionService,
LoggedInContext loggedInContext,
string projectCode,
Guid projectId,
LexBoxDbContext dbContext,
[Service] IEmailService emailService)
{
await permissionService.AssertCanAskToJoinProject(projectCode);
await permissionService.AssertCanAskToJoinProject(projectId);

var user = await dbContext.Users.FindAsync(loggedInContext.User.Id);
if (user is null) throw new UnauthorizedAccessException();
Expand All @@ -246,7 +246,7 @@ public async Task<IQueryable<Project>> AskToJoinProject(
var project = await dbContext.Projects
.Include(p => p.Users)
.ThenInclude(u => u.User)
.Where(p => p.Code == projectCode)
.Where(p => p.Id == projectId)
.FirstOrDefaultAsync();
NotFoundException.ThrowIfNull(project);

Expand All @@ -256,7 +256,7 @@ public async Task<IQueryable<Project>> AskToJoinProject(
if (manager.User is null) continue;
await emailService.SendJoinProjectRequestEmail(manager.User, user, project);
}
return dbContext.Projects.Where(p => p.Id == project.Id);
return dbContext.Projects.Where(p => p.Id == projectId);
}

[Error<NotFoundException>]
Expand Down
2 changes: 1 addition & 1 deletion frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ input AddProjectToOrgInput {
}

input AskToJoinProjectInput {
projectCode: String!
projectId: UUID!
}

input BooleanOperationFilterInput {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ the [Linguistics Institute at Payap University](https://li.payap.ac.th/) in Chia
"maybe_related_description": "Perhaps you want to join one of these instead?",
"ask_to_join": "Ask to join",
"no_thanks": "No thanks, create a new project",
"join_request_sent": "Your request to join the {projectName} project has been sent to the project manager(s)",
"description": "Description",
"name_missing": "Project name required",
"retention_policy": "Purpose",
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/routes/(authenticated)/project/create/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import t from '$lib/i18n';
import { TitlePage } from '$lib/layout';
import { z } from 'zod';
import { _createProject, _projectCodeAvailable } from './+page';
import { _askToJoinProject, _createProject, _projectCodeAvailable } from './+page';
import AdminContent from '$lib/layout/AdminContent.svelte';
import { useNotifications } from '$lib/notify';
import { Duration, deriveAsync, deriveAsyncIfDefined } from '$lib/util/time';
Expand Down Expand Up @@ -168,12 +168,13 @@
);
}
let selectedProjectCode: string;
let selectedProject: { name: string, id: string } | undefined = undefined;
let showRelatedProjects = true;
function askToJoinProject(projectCode: string): void {
// TODO: Implement
console.log('Will ask to join', projectCode);
async function askToJoinProject(projectId: string, projectName: string): Promise<void> {
await _askToJoinProject(projectId);
notifySuccess($t('project.create.join_request_sent', { projectName }))
await goto('/');
}
</script>

Expand Down Expand Up @@ -262,7 +263,7 @@
{#each $relatedProjects as proj}
<div class="form-control w-full">
<label class="label cursor-pointer justify-normal pb-0">
<input id={`extra-projects-${proj.code}`} type="radio" bind:group={selectedProjectCode} value={proj.code} class="radio mr-2" />
<input id={`extra-projects-${proj.code}`} type="radio" bind:group={selectedProject} value={proj} class="radio mr-2" />
<span class="label-text inline-flex items-center gap-2">
{proj.name} ({proj.code}) <br/>
{proj.description}
Expand All @@ -281,8 +282,8 @@
<Button
class="mr-2"
variant="btn-primary"
disabled={!selectedProjectCode}
on:click={() => askToJoinProject(selectedProjectCode)}
disabled={!selectedProject}
on:click={() => askToJoinProject(selectedProject.id, selectedProject.name)}
>
{$t('project.create.ask_to_join')}
</Button>
Expand Down
24 changes: 23 additions & 1 deletion frontend/src/routes/(authenticated)/project/create/+page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { $OpResult, CreateProjectInput, CreateProjectMutation, ProjectsByLangCodeAndOrgQuery } from '$lib/gql/types';
import type { $OpResult, AskToJoinProjectMutation, CreateProjectInput, CreateProjectMutation, ProjectsByLangCodeAndOrgQuery } from '$lib/gql/types';
import { getClient, graphql } from '$lib/gql';

import type { PageLoadEvent } from './$types';
Expand Down Expand Up @@ -107,3 +107,25 @@ export async function _getProjectsByLangCodeAndOrg(input: { orgId: string, langC
);
return results.projectsByLangCodeAndOrg;
}

export async function _askToJoinProject(projectId: string): $OpResult<AskToJoinProjectMutation> {
const result = await getClient().mutation(
//language=GraphQL
graphql(`
mutation askToJoinProject($input: AskToJoinProjectInput!) {
askToJoinProject(input: $input) {
project {
id
}
errors {
... on DbError {
code
}
}
}
}
`),
{ input: { projectId } });
return result;
//
}

0 comments on commit 5bf54e2

Please sign in to comment.