Skip to content

Commit

Permalink
remove @action decorator and type route templates
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryD committed Dec 13, 2024
1 parent 67930e0 commit f299b77
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 113 deletions.
9 changes: 3 additions & 6 deletions app/components/forms/register.gts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { RegisterChangeset } from 'ember-boilerplate/changesets/register';
import TpkForm from '@triptyk/ember-input-validation/components/tpk-form';
import type validationsRegister from 'ember-boilerplate/validations/register';
import Component from '@glimmer/component';
import { action } from '@ember/object';

export interface FormsRegisterSignature {
Args: {
Expand All @@ -19,13 +18,11 @@ export interface FormsRegisterSignature {
}

export default class FormsRegister extends Component<FormsRegisterSignature> {
@action
setBirthdate(date: unknown) {
setBirthdate = (date: unknown) => {
this.args.changeset.set('birthDate', date as Date);
}

@action
selectCategory(category: unknown) {
selectCategory = (category: unknown) => {
this.args.changeset.set('category', category as string);
}

Expand All @@ -35,7 +32,7 @@ export default class FormsRegister extends Component<FormsRegisterSignature> {
@onSubmit={{@saveFunction}}
@validationSchema={{@validationSchema}}
data-test-form="register"
class="px-4 py-8 mt-8 bg-white rounded-lg shadow sm:px-10 sm:mx-auto sm:w-full sm:max-w-5xl grid grid-cols-12 gap-x-6"
class="px-4 py-8 mt-8 bg-white rounded-lg shadow-md shadow sm:px-10 sm:mx-auto sm:w-full sm:max-w-5xl grid grid-cols-12 gap-x-6"
...attributes
as |F|
>
Expand Down
4 changes: 2 additions & 2 deletions app/components/login-layout.gts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export interface LoginLayoutSignature {

const LoginLayout: TOC<LoginLayoutSignature> = <template>
<div
class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8 bg-primary-content h-screen"
class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8 h-screen"
...attributes
>
<h1 class="text-center text-white">
<h1 class="text-center">
{{@title}}
</h1>
<div class="mx-auto w-full max-w-5xl">
Expand Down
2 changes: 1 addition & 1 deletion app/routes/404.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Route from '@ember/routing/route';

export default class NotFound extends Route {}
export default class NotFoundRoute extends Route {}
2 changes: 1 addition & 1 deletion app/routes/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { IntlService } from 'ember-intl';
import type SessionService from 'ember-simple-auth/services/session';
import { setupWorker } from 'msw/browser';

export default class Application extends Route {
export default class ApplicationRoute extends Route {
@service declare session: SessionService;
@service declare currentUser: CurrentUserService;
@service declare intl: IntlService;
Expand Down
2 changes: 1 addition & 1 deletion app/routes/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { service } from '@ember/service';

import type SessionService from 'ember-simple-auth/services/session';

export default class Login extends Route {
export default class LoginRoute extends Route {
@service declare session: SessionService;

beforeModel() {
Expand Down
4 changes: 0 additions & 4 deletions app/routes/register.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import Route from '@ember/routing/route';

export interface RegisterRouteParams {}

export type RegisterRouteModel = Resolved<ReturnType<RegisterRoute['model']>>;

export default class RegisterRoute extends Route {
model() {
return {};
Expand Down
5 changes: 2 additions & 3 deletions app/styles/app.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import url("tailwindcss/base");
@import url("tailwindcss/components");
@import url("tailwindcss/utilities");
@import url("flash-messages.css");
@import url("loading.css");
@import url("@eonasdan/tempus-dominus/dist/css/tempus-dominus.css");
@import url("ember-power-select/vendor/ember-power-select.css");
Expand All @@ -16,9 +15,9 @@ h2 {
}

h3 {
@apply text-text text-base;
@apply text-base;
}

h4 {
@apply text-text text-lg mb-4 font-bold pb-4 border-b border-text/30;
@apply text-lg mb-4 font-bold pb-4 border-b;
}
37 changes: 0 additions & 37 deletions app/styles/flash-messages.css

This file was deleted.

9 changes: 4 additions & 5 deletions app/templates/404.gts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import Component from '@glimmer/component';
import { on } from '@ember/modifier';
import { action } from '@ember/object';

import t from 'ember-intl/helpers/t';
import RouteTemplate from 'ember-route-template';
import type { RouteTemplateSignature } from 'ember-boilerplate/utils/route-template';
import type NotFoundRoute from 'ember-boilerplate/routes/404';

export interface NotFoundRouteComponentSignature {}

class NotFoundRouteComponent extends Component<NotFoundRouteComponentSignature> {
@action
comeback() {
class NotFoundRouteComponent extends Component<RouteTemplateSignature<NotFoundRoute>> {
comeback = () => {
window.history.back();
}

Expand Down
34 changes: 32 additions & 2 deletions app/templates/application.gts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,45 @@ import HeadLayout from 'ember-cli-head/components/head-layout';
import RouteTemplate from 'ember-route-template';

import type FlashMessageService from 'ember-cli-flash/services/flash-messages';
import type { RouteTemplateSignature } from 'ember-boilerplate/utils/route-template';
import type ApplicationRoute from 'ember-boilerplate/routes/application';

class ApplicationRouteComponent extends Component {
class ApplicationRouteComponent extends Component<RouteTemplateSignature<ApplicationRoute>> {
@service declare flashMessages: FlashMessageService;

flashTypes = (type: 'Success' | 'Warning' | 'Danger') => {
console.log(type);

if (type === 'Warning') {
return 'alert-warning';
}

if (type === 'Danger') {
return 'alert-danger';
}

return 'alert-success';
}

<template>
<HeadLayout />
<div class="fixed z-10 top-4 right-4">
{{#each this.flashMessages.arrangedQueue as |flash|}}
<FlashMessage @flash={{flash}} />
<FlashMessage class="mb-2" @flash={{flash}} as |_ flash|>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
class="h-6 w-6 shrink-0 stroke-current">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
{{!-- @glint-expect-error --}}
<span>{{flash.message}}</span>
</FlashMessage>
{{/each}}
</div>
{{outlet}}
Expand Down
13 changes: 6 additions & 7 deletions app/templates/forgot-password.gts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';

import { service } from '@ember/service';

import { ForgotPasswordChangeset } from 'ember-boilerplate/changesets/forgot-password';
Expand All @@ -12,26 +12,25 @@ import { tracked } from 'tracked-built-ins';
import type Router from '@ember/routing/router';
import type FlashMessageService from 'ember-cli-flash/services/flash-messages';
import RequestManager from '@ember-data/request';
import type ForgotPasswordRoute from 'ember-boilerplate/routes/forgot-password';
import type { RouteTemplateSignature } from 'ember-boilerplate/utils/route-template';

interface PagesForgotPasswordArgs {}

class PagesForgotPassword extends Component<PagesForgotPasswordArgs> {
class PagesForgotPassword extends Component<RouteTemplateSignature<ForgotPasswordRoute>> {
@service declare router: Router;
@service declare requestManager: RequestManager;
@service declare flashMessages: FlashMessageService;
@tracked changeset: ForgotPasswordChangeset;

validationSchema = forgotPasswordSchema;

constructor(owner: unknown, args: PagesForgotPasswordArgs) {
constructor(owner: unknown, args: RouteTemplateSignature<ForgotPasswordRoute>['Args']) {
super(owner, args);
this.changeset = new ForgotPasswordChangeset({
email: '',
});
}

@action
async sendRecoveryRequest(changeset: ForgotPasswordChangeset) {
sendRecoveryRequest = async (changeset: ForgotPasswordChangeset) => {
try {
await this.requestManager.request({
url: '/auth/forgot-password',
Expand Down
16 changes: 7 additions & 9 deletions app/templates/login.gts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

import { service } from '@ember/service';
import { waitFor } from '@ember/test-waiters';

Expand All @@ -15,10 +15,10 @@ import type RouterService from '@ember/routing/router-service';
import type CurrentUserService from 'ember-boilerplate/services/current-user';
import type FlashMessageService from 'ember-cli-flash/services/flash-messages';
import type SessionService from 'ember-simple-auth/services/session';
import type { RouteTemplateSignature } from 'ember-boilerplate/utils/route-template';
import type LoginRoute from 'ember-boilerplate/routes/login';

interface PagesLoginArgs {}

class PagesLogin extends Component<PagesLoginArgs> {
class PagesLogin extends Component<RouteTemplateSignature<LoginRoute>> {
@service declare flashMessages: FlashMessageService;
@service declare currentUser: CurrentUserService;
@service declare router: RouterService;
Expand All @@ -28,17 +28,15 @@ class PagesLogin extends Component<PagesLoginArgs> {

@tracked changeset: LoginChangeset;

public constructor(owner: unknown, args: PagesLoginArgs) {
public constructor(owner: unknown, args: RouteTemplateSignature<LoginRoute>['Args']) {
super(owner, args);
this.changeset = new LoginChangeset({
email: '',
password: '',
});
}

@action
@waitFor
async login(changeset: LoginChangeset) {
login = waitFor(async (changeset: LoginChangeset) => {
try {
await this.session.authenticate('authenticator:jwt', {
email: changeset.get('email'),
Expand All @@ -49,7 +47,7 @@ class PagesLogin extends Component<PagesLoginArgs> {
} catch (e) {
this.flashMessages.danger('Username or password incorrect');
}
}
});

<template>
<LoginLayout @title={{t "components.templates.login.title"}}>
Expand Down
18 changes: 8 additions & 10 deletions app/templates/register.gts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { service } from '@ember/service';

import { RegisterChangeset } from 'ember-boilerplate/changesets/register';
Expand All @@ -14,20 +13,18 @@ import type RegisterChangesetService from 'ember-boilerplate/services/changesets
import type ErrorHandlerService from 'ember-boilerplate/services/error-handler';
import type FlashMessageService from 'ember-cli-flash/services/flash-messages';
import { array } from '@ember/helper';
import type { RouteTemplateSignature } from 'ember-boilerplate/utils/route-template';
import type RegisterRoute from 'ember-boilerplate/routes/register';

export interface RegisterRouteComponentSignature {
Args: {};
}

class RegisterRouteComponent extends Component<RegisterRouteComponentSignature> {
class RegisterRouteComponent extends Component<RouteTemplateSignature<RegisterRoute>> {
@service declare flashMessages: FlashMessageService;
@service('changesets/register') declare register: RegisterChangesetService;
@service declare errorHandler: ErrorHandlerService;
@tracked declare changeset: RegisterChangeset;

validationSchema = formsRegisterSchema;

constructor(owner: unknown, args: RegisterRouteComponentSignature['Args']) {
constructor(owner: unknown, args: RouteTemplateSignature<RegisterRoute>['Args']) {
super(owner, args);
this.changeset = new RegisterChangeset({
email: '',
Expand All @@ -47,15 +44,16 @@ class RegisterRouteComponent extends Component<RegisterRouteComponentSignature>
});
}

@action
async saveRegister(changeset: RegisterChangeset) {
saveRegister = async (changeset: RegisterChangeset) => {
const user = await this.register.save(changeset);

if (user.isErr) {
return this.errorHandler.handle(user.error.message);
}

return this.flashMessages.success('components.templates.register.success_message');
return this.flashMessages.success('components.templates.register.success_message', {
timeout: 5000000
});
}

<template>
Expand Down
20 changes: 8 additions & 12 deletions app/templates/reset-password.gts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';

import { service } from '@ember/service';

import { ResetPasswordChangeset } from 'ember-boilerplate/changesets/reset-password';
Expand All @@ -13,34 +13,30 @@ import { tracked } from 'tracked-built-ins';
import type RouterService from '@ember/routing/router-service';
import type FlashMessageService from 'ember-cli-flash/services/flash-messages';
import type RequestManager from '@ember-data/request';
import type ResetPasswordRoute from 'ember-boilerplate/routes/reset-password';
import type { RouteTemplateSignature } from 'ember-boilerplate/utils/route-template';
import type ResetPasswordController from 'ember-boilerplate/controllers/reset-password';

interface ResetPasswordRouteComponentSignature {
Args: {
token: string;
};
}

class ResetPasswordRouteComponent extends Component<ResetPasswordRouteComponentSignature> {
class ResetPasswordRouteComponent extends Component<RouteTemplateSignature<ResetPasswordRoute, ResetPasswordController>> {
@service declare requestManager: RequestManager;
@service declare router: RouterService;
@service declare flashMessages: FlashMessageService;
@tracked changeset: ResetPasswordChangeset;

validationSchema = passwordRecoveryValidation;

constructor(owner: unknown, args: ResetPasswordRouteComponentSignature['Args']) {
constructor(owner: unknown, args: RouteTemplateSignature<ResetPasswordRoute, ResetPasswordController>['Args']) {
super(owner, args);
this.changeset = new ResetPasswordChangeset({
password: '',
confirmPassword: '',
});
}

@action
async recoverPassword(changeset: ResetPasswordChangeset) {
recoverPassword = async (changeset: ResetPasswordChangeset) => {
try {
await this.requestManager.request({
url: `auth/set-password/${this.args.token}`,
url: `auth/set-password/${this.args.model.token}`,
body: JSON.stringify({
password: changeset.get('password'),
}),
Expand Down
Loading

0 comments on commit f299b77

Please sign in to comment.