Skip to content

Commit

Permalink
add checkbox & canInvite variable
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHo Park committed Jul 17, 2024
1 parent 6737890 commit 561b42f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
9 changes: 7 additions & 2 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public record CreateProjectResponse(Guid? Id, CreateProjectResult Result);
[UseMutationConvention]
[UseFirstOrDefault]
[UseProjection]
public async Task<IQueryable<Project>> AddProjectMember(IPermissionService permissionService,
public async Task<IQueryable<Project>> AddProjectMember(
IPermissionService permissionService,
LoggedInContext loggedInContext,
AddProjectMemberInput input,
LexBoxDbContext dbContext,
Expand All @@ -87,12 +88,16 @@ public async Task<IQueryable<Project>> AddProjectMember(IPermissionService permi
{
throw NotFoundException.ForType<User>();
}
else
else if (input.canInvite)
{
var manager = loggedInContext.User;
await emailService.SendCreateAccountEmail(email, input.ProjectId, input.Role, manager.Name, project.Name);
throw new ProjectMemberInvitedByEmail("Invitation email sent");
}
else
{
throw NotFoundException.ForType<User>();
}
}
if (user.Projects.Any(p => p.ProjectId == input.ProjectId))
{
Expand Down
2 changes: 1 addition & 1 deletion backend/LexBoxApi/Models/Project/ProjectMemberInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace LexBoxApi.Models.Project;

public record AddProjectMemberInput(Guid ProjectId, string UsernameOrEmail, ProjectRole Role);
public record AddProjectMemberInput(Guid ProjectId, string UsernameOrEmail, ProjectRole Role, bool canInvite);

public record BulkAddProjectMembersInput(Guid? ProjectId, string[] Usernames, ProjectRole Role, string PasswordHash);

Expand Down
1 change: 1 addition & 0 deletions frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ input AddProjectMemberInput {
projectId: UUID!
usernameOrEmail: String!
role: ProjectRole!
canInvite: Boolean!
}

input AddProjectToOrgInput {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/components/modals/FormModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<slot name="extraActions" />
</svelte:fragment>
<svelte:fragment slot="actions" let:submitting>
<slot name="checkbox"/>
{#if !done}
<SubmitButton form="modalForm" variant={submitVariant} loading={submitting}>
<slot name="submitText" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import { page } from '$app/stores'
import UserTypeahead from '$lib/forms/UserTypeahead.svelte';
import { SupHelp, helpLinks } from '$lib/components/help';
import Checkbox from '$lib/forms/Checkbox.svelte';
export let projectId: string;
const schema = z.object({
usernameOrEmail: z.string().trim()
.min(1, $t('project_page.add_user.empty_user_field'))
.refine((value) => !value.includes('@') || isEmail(value), { message: $t('form.invalid_email') }),
role: z.enum([ProjectRole.Editor, ProjectRole.Manager]).default(ProjectRole.Editor),
canInvite: z.boolean().default(false),
});
let formModal: FormModal<typeof schema>;
$: form = formModal?.form();
Expand All @@ -30,6 +32,7 @@
projectId,
usernameOrEmail: $form.usernameOrEmail,
role: $form.role,
canInvite: $form.canInvite,
});
if (error?.byType('NotFoundError')) {
Expand Down Expand Up @@ -93,6 +96,15 @@
/>
{/if}
<ProjectRoleSelect bind:value={$form.role} error={errors.role} />
<span slot="checkbox">
<Checkbox
id="invite"
label={'Invite'}
variant="checkbox-warning"
labelColor="text-warning"
bind:value={$form.canInvite}
/>
</span>
<span slot="submitText">
{#if $form.usernameOrEmail.includes('@')}
{$t('project_page.add_user.submit_button_email')}
Expand Down

0 comments on commit 561b42f

Please sign in to comment.