-
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 branch 'main' into jeffdaley/products-route
- Loading branch information
Showing
24 changed files
with
865 additions
and
204 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
node_modules | ||
/web/.pnp.* | ||
/web/.yarn/* | ||
/web/.eslintcache | ||
/web/dist | ||
|
||
# Terraform related | ||
|
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,44 @@ | ||
module.exports = { | ||
plugins: ["ember", "@typescript-eslint"], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "./tsconfig.json", | ||
}, | ||
ignorePatterns: ["*.js", "/mirage/**/*", "/node_modules/**/*", "/dist/**/*"], | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
], | ||
|
||
rules: { | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-unsafe-member-access": "off", | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/no-unsafe-assignment": "off", | ||
"@typescript-eslint/no-unsafe-argument": "off", | ||
"@typescript-eslint/no-unsafe-return": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/no-redundant-type-constituents": "off", | ||
"@typescript-eslint/require-await": "off", | ||
"@typescript-eslint/no-floating-promises": "off", | ||
"@typescript-eslint/unbound-method": "off", | ||
"@typescript-eslint/no-misused-promises": "off", | ||
"@typescript-eslint/restrict-template-expressions": "off", | ||
"@typescript-eslint/no-misused-new": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"@typescript-eslint/restrict-plus-operands": "off", | ||
"@typescript-eslint/await-thenable": "off", | ||
"@typescript-eslint/no-unsafe-enum-comparison": "off", | ||
"@typescript-eslint/no-unnecessary-type-assertion": "off", | ||
"no-case-declarations": "off", | ||
"no-fallthrough": "off", | ||
"prefer-const": "off", | ||
"no-empty-pattern": "off", | ||
"no-control-regex": "off", | ||
"no-self-assign": "off", | ||
"prefer-rest-params": "off", | ||
"no-empty": "off", | ||
}, | ||
}; |
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
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 |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import Route from "@ember/routing/route"; | ||
import { inject as service } from "@ember/service"; | ||
import ProductAreasService from "hermes/services/product-areas"; | ||
|
||
interface AuthenticatedNewDocRouteParams { | ||
docType: string; | ||
} | ||
|
||
export default class AuthenticatedNewDocRoute extends Route { | ||
@service declare productAreas: ProductAreasService; | ||
|
||
queryParams = { | ||
docType: { | ||
refreshModel: true, | ||
}, | ||
}; | ||
|
||
model(params: AuthenticatedNewDocRouteParams) { | ||
async model(params: AuthenticatedNewDocRouteParams) { | ||
if (!this.productAreas.index) { | ||
await this.productAreas.fetch.perform(); | ||
} | ||
|
||
return params.docType; | ||
} | ||
} |
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,3 @@ | ||
import Route from "@ember/routing/route"; | ||
|
||
export default class AuthenticatedNewProjectRoute extends Route {} |
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,3 @@ | ||
{{page-title "Start a project"}} | ||
|
||
<New::ProjectForm /> |
Oops, something went wrong.