-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into jfreda/api-v2
- Loading branch information
Showing
29 changed files
with
513 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<form | ||
data-test-project-form | ||
{{on "submit" this.maybeSubmitForm}} | ||
class="mx-auto mb-10 max-w-xl" | ||
> | ||
<div class="space-y-4"> | ||
<h1>Start a project</h1> | ||
</div> | ||
<div class="mt-7 grid gap-7"> | ||
<Hds::Form::Textarea::Field | ||
{{on "keydown" this.onKeydown}} | ||
{{auto-height-textarea}} | ||
{{autofocus}} | ||
data-test-title | ||
@value={{this.title}} | ||
name="title" | ||
placeholder="Enter a project title" | ||
as |F| | ||
> | ||
<F.Label>Title</F.Label> | ||
{{#if this.errorIsShown}} | ||
<F.Error data-test-title-error> | ||
Title is required. | ||
</F.Error> | ||
{{/if}} | ||
</Hds::Form::Textarea::Field> | ||
|
||
<Hds::Form::Textarea::Field | ||
data-test-description | ||
{{on "keydown" this.onKeydown}} | ||
@value={{this.description}} | ||
rows="2" | ||
placeholder="A short summary of your project" | ||
name="description" | ||
as |F| | ||
> | ||
<F.Label>Description</F.Label> | ||
</Hds::Form::Textarea::Field> | ||
|
||
{{! TODO: Add Jira integration }} | ||
|
||
</div> | ||
<Hds::Button | ||
data-test-submit | ||
@text="Create project" | ||
@isFullWidth={{true}} | ||
type="submit" | ||
/> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { action } from "@ember/object"; | ||
import RouterService from "@ember/routing/router-service"; | ||
import { next } from "@ember/runloop"; | ||
import { inject as service } from "@ember/service"; | ||
import Component from "@glimmer/component"; | ||
import { tracked } from "@glimmer/tracking"; | ||
import FlashMessageService from "ember-cli-flash/services/flash-messages"; | ||
import { task } from "ember-concurrency"; | ||
import FetchService from "hermes/services/fetch"; | ||
import cleanString from "hermes/utils/clean-string"; | ||
|
||
interface NewProjectFormComponentSignature { | ||
Args: {}; | ||
} | ||
|
||
export default class NewProjectFormComponent extends Component<NewProjectFormComponentSignature> { | ||
@service("fetch") declare fetchSvc: FetchService; | ||
@service declare router: RouterService; | ||
@service declare flashMessages: FlashMessageService; | ||
|
||
@tracked protected title: string = ""; | ||
@tracked protected description: string = ""; | ||
|
||
@tracked protected formIsValid = false; | ||
@tracked protected errorIsShown = false; | ||
|
||
@action maybeSubmitForm(event?: SubmitEvent) { | ||
if (event) { | ||
event.preventDefault(); | ||
} | ||
|
||
this.validateForm(); | ||
|
||
if (this.formIsValid) { | ||
this.createProject.perform(); | ||
} | ||
} | ||
|
||
private validateForm() { | ||
this.errorIsShown = this.title.length === 0; | ||
this.formIsValid = this.title.length > 0; | ||
} | ||
|
||
@action protected onKeydown(e: KeyboardEvent) { | ||
if (e.key === "Enter") { | ||
// Replace newline function with submit action | ||
e.preventDefault(); | ||
this.maybeSubmitForm(); | ||
} | ||
if (this.errorIsShown) { | ||
// Validate once the input value are captured | ||
next("afterRender", () => { | ||
this.validateForm(); | ||
}); | ||
} | ||
} | ||
|
||
private createProject = task(async () => { | ||
try { | ||
const project = await this.fetchSvc | ||
.fetch("/api/v1/projects", { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
title: cleanString(this.title), | ||
description: cleanString(this.description), | ||
}), | ||
}) | ||
.then((response) => response?.json()); | ||
this.router.transitionTo("authenticated.projects.project", project.id); | ||
} catch (error: unknown) { | ||
const typedError = error as Error; | ||
|
||
this.flashMessages.add({ | ||
title: "Error creating project", | ||
message: typedError.message, | ||
type: "critical", | ||
timeout: 6000, | ||
extendedTimeout: 1000, | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
declare module "@glint/environment-ember-loose/registry" { | ||
export default interface Registry { | ||
"New::ProjectForm": typeof NewProjectFormComponent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.