This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(manager): add form to creating custom tip
- Loading branch information
1 parent
e69b302
commit 35b70e7
Showing
29 changed files
with
417 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CREATE TABLE public.custom_tip ( | ||
"id" character varying NOT NULL, | ||
"title" character varying NOT NULL, | ||
"text" character varying NOT NULL, | ||
"link" character varying, | ||
"expireAt" timestamp with time zone NOT NULL, | ||
"important" BOOLEAN NOT NULL DEFAULT FALSE | ||
); | ||
|
||
ALTER TABLE ONLY public.custom_tip | ||
ADD CONSTRAINT "PK_custom_tip_id" PRIMARY KEY ("id"); | ||
|
||
#DOWN | ||
|
||
DROP TABLE public.custom_tip; |
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,25 @@ | ||
import { Injectable } from '@nestjs/common' | ||
|
||
import { EntitySaver } from '@back/db/EntitySaver' | ||
import { CustomTipModel } from '@shared/models/mind/CustomTipModel' | ||
import { IdGenerator } from '@back/utils/infrastructure/IdGenerator/IdGenerator' | ||
|
||
import { DisabledTip } from '../domain/DisabledTip.entity' | ||
import { CustomTip } from '../domain/CustomTip.entity' | ||
|
||
@Injectable() | ||
export class TipsCreator { | ||
public constructor( | ||
private readonly entitySaver: EntitySaver, | ||
private readonly idGenerator: IdGenerator, | ||
) {} | ||
|
||
public async createCustom(fields: CustomTipModel): Promise<void> { | ||
const id = await this.idGenerator.getId() | ||
const { title, text, expireAt, important, link } = fields | ||
|
||
const tip = new CustomTip(id, title, text, expireAt, important, link) | ||
|
||
await this.entitySaver.save(tip) | ||
} | ||
} |
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,40 @@ | ||
import { Column, Entity, PrimaryColumn } from 'typeorm' | ||
|
||
import { CustomTipModel } from '@shared/models/mind/CustomTipModel' | ||
|
||
@Entity() | ||
export class CustomTip implements CustomTipModel { | ||
@PrimaryColumn() | ||
public readonly id: string | ||
|
||
@Column() | ||
public readonly title: string | ||
|
||
@Column() | ||
public readonly text: string | ||
|
||
@Column() | ||
public readonly link?: string | ||
|
||
@Column() | ||
public readonly expireAt: Date | ||
|
||
@Column() | ||
public readonly important: boolean | ||
|
||
public constructor( | ||
id: string, | ||
title: string, | ||
text: string, | ||
expireAt: Date, | ||
important: boolean = false, | ||
link?: string, | ||
) { | ||
this.id = id | ||
this.title = title | ||
this.text = text | ||
this.expireAt = expireAt | ||
this.important = important | ||
this.link = link | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
back/src/mind/presentation/http/request/CustomTipRequest.ts
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,20 @@ | ||
import { ApiModelProperty } from '@nestjs/swagger' | ||
|
||
import { CustomTipModel } from '@shared/models/mind/CustomTipModel' | ||
|
||
export class CustomTipRequest implements CustomTipModel { | ||
@ApiModelProperty({ example: 'Alert' }) | ||
public readonly title: string | ||
|
||
@ApiModelProperty({ example: 'All cool' }) | ||
public readonly text: string | ||
|
||
@ApiModelProperty({ example: 'https://google.com', required: false }) | ||
public readonly link?: string | ||
|
||
@ApiModelProperty({ example: new Date() }) | ||
public readonly expireAt: Date | ||
|
||
@ApiModelProperty({ example: true }) | ||
public readonly important: boolean | ||
} |
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,9 +1,11 @@ | ||
import * as React from 'react' | ||
|
||
import { Manager } from '@front/features/manager' | ||
|
||
export default class HisotryPage extends React.Component { | ||
public static isSecure = true | ||
|
||
public render() { | ||
return <p>MANAGER</p> | ||
return <Manager /> | ||
} | ||
} |
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,10 @@ | ||
import { fetchOrFail } from '@front/domain/store' | ||
import { CustomTipModel } from '@shared/models/mind/CustomTipModel' | ||
|
||
import { createTipRequest } from '../api/createTipRequest' | ||
import { actions as tipFetchingActions } from '../reducer/createTipFetching' | ||
|
||
export const createTip = (tip: CustomTipModel) => | ||
fetchOrFail(tipFetchingActions, async (_, getApi) => { | ||
await createTipRequest(getApi())(tip) | ||
}) |
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,7 @@ | ||
import { Api } from '@front/domain/api' | ||
import { CustomTipModel } from '@shared/models/mind/CustomTipModel' | ||
|
||
export const createTipRequest = (api: Api) => ( | ||
tip: CustomTipModel, | ||
): Promise<void> => | ||
api.client.post('/mind/tip/create', tip).then(response => response.data) |
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,7 @@ | ||
import { createFetchingRedux, FetchingState } from 'redux-clear' | ||
|
||
type State = FetchingState | ||
|
||
const { reducer, actions } = createFetchingRedux('manager/create-tip-fetching') | ||
|
||
export { reducer, actions, State } |
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,13 +1,19 @@ | ||
import { combineReducers } from 'redux' | ||
|
||
import { reducer as tipsReducer, State as TipsState } from './tips' | ||
import { | ||
reducer as createTipFetchingReducer, | ||
State as CreateTipTipState, | ||
} from './createTipFetching' | ||
|
||
interface State { | ||
tips: TipsState | ||
createTipFetching: CreateTipTipState | ||
} | ||
|
||
const reducer = combineReducers<State>({ | ||
tips: tipsReducer, | ||
createTipFetching: createTipFetchingReducer, | ||
}) | ||
|
||
export { reducer, State } |
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,4 @@ | ||
import { State } from '@front/domain/store' | ||
|
||
export const getCreateTipFetching = (state: State) => | ||
state.mind.createTipFetching |
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,23 @@ | ||
import { Field, FieldRenderProps } from 'react-final-form' | ||
import { Diff } from 'utility-types' | ||
|
||
import { | ||
Checkbox as JustCheckbox, | ||
CheckboxProps, | ||
} from '@front/ui/components/form/checkbox' | ||
|
||
interface OwnProps { | ||
name: string | ||
} | ||
|
||
type ComponentProps = Diff<CheckboxProps, FieldRenderProps['input']> | ||
|
||
export const Checkbox = ({ | ||
name, | ||
...componentProps | ||
}: OwnProps & ComponentProps) => ( | ||
<Field | ||
name={name} | ||
render={({ input }) => <JustCheckbox {...componentProps} {...input} />} | ||
/> | ||
) |
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,23 @@ | ||
import { Field, FieldRenderProps } from 'react-final-form' | ||
import { Diff } from 'utility-types' | ||
|
||
import { | ||
TextArea as JustTextArea, | ||
TextAreaProps, | ||
} from '@front/ui/components/form/text-area' | ||
|
||
interface OwnProps { | ||
name: string | ||
} | ||
|
||
type ComponentProps = Diff<TextAreaProps, FieldRenderProps['input']> | ||
|
||
export const TextArea = ({ | ||
name, | ||
...componentProps | ||
}: OwnProps & ComponentProps) => ( | ||
<Field | ||
name={name} | ||
render={({ input }) => <JustTextArea {...componentProps} {...input} />} | ||
/> | ||
) |
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,7 +1,9 @@ | ||
export { AutoComplete } from './components/AutoComplete' | ||
export { Checkbox } from './components/Checkbox' | ||
export { Input } from './components/Input' | ||
export { InputMoney } from './components/InputMoney' | ||
export { Select } from './components/Select' | ||
export { EnumSelect } from './components/EnumSelect' | ||
export { DatePicker } from './components/DatePicker' | ||
export { TextArea } from './components/TextArea' | ||
export { Toggle } from './components/Toggle' |
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,11 @@ | ||
import { Container } from '@front/ui/components/layout/container' | ||
|
||
import { CreateTip } from './features/create-tip' | ||
|
||
export const Manager = () => { | ||
return ( | ||
<Container> | ||
<CreateTip /> | ||
</Container> | ||
) | ||
} |
48 changes: 48 additions & 0 deletions
48
front/src/features/manager/features/create-tip/CreateTip.css
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,48 @@ | ||
.form { | ||
display: grid; | ||
|
||
grid-template: | ||
'title title ' | ||
'content content' | ||
'link expire ' | ||
'important submit ' | ||
/ 1fr 1fr; | ||
|
||
@media (max-width: 768px) { | ||
grid-template: | ||
'title' | ||
'content' | ||
'link' | ||
'expire' | ||
'important' | ||
'submit'; | ||
} | ||
|
||
align-items: end; | ||
gap: 16px; | ||
|
||
& > *:nth-child(1) { | ||
grid-area: title; | ||
} | ||
|
||
& > *:nth-child(2) { | ||
grid-area: content; | ||
} | ||
|
||
& > *:nth-child(3) { | ||
grid-area: link; | ||
} | ||
|
||
& > *:nth-child(4) { | ||
grid-area: expire; | ||
} | ||
|
||
& > *:nth-child(5) { | ||
grid-area: important; | ||
align-self: center; | ||
} | ||
|
||
& > *:nth-child(6) { | ||
grid-area: submit; | ||
} | ||
} |
Oops, something went wrong.