Commit f3b32b5c authored by Juan Manuel Solaro's avatar Juan Manuel Solaro

(feat) date selector should validate date and adapt code as per review

1 merge request!494WIP: epic/post-scheduler
Pipeline #79426898 failed with stages
in 8 minutes and 16 seconds
......@@ -101,7 +101,7 @@ import { SettingsService } from '../modules/settings/settings.service';
import { ThemeService } from './services/theme.service';
import { HorizontalInfiniteScroll } from './components/infinite-scroll/horizontal-infinite-scroll.component';
import { ReferralsLinksComponent } from '../modules/wallet/tokens/referrals/links/links.component';
import { PosterDateSelectorComponent } from './components/poster-date-selector/poster-date-selector.component';
import { PosterDateSelectorComponent } from './components/poster-date-selector/selector.component';
import { ShareModalComponent } from '../modules/modals/share/share';
@NgModule({
......
......@@ -5,7 +5,7 @@ import {
fakeAsync,
tick,
} from '@angular/core/testing';
import { PosterDateSelectorComponent } from './poster-date-selector.component';
import { PosterDateSelectorComponent } from './selector.component';
import { MaterialDateTimePickerDirective } from '../../directives/material/datetimepicker.directive';
import { FormsModule } from '@angular/forms';
import { MockComponent } from '../../../utils/mock';
......
......@@ -4,18 +4,25 @@ import { DatePipe } from '@angular/common';
@Component({
moduleId: module.id,
selector: 'm-poster-date-selector',
templateUrl: 'poster-date-selector.component.html',
templateUrl: 'selector.component.html',
providers: [DatePipe],
})
export class PosterDateSelectorComponent {
@Input() date: string;
@Output() dateChange: EventEmitter<any> = new EventEmitter<any>();
@Output() onError: EventEmitter<String> = new EventEmitter<String>();
@Input() dateFormat: string = 'short';
tooltipDate: string;
onDateChange(newDate) {
const validation = this.validate(newDate);
if (validation !== true) {
this.onError.emit(validation);
return;
}
this.date = this.tooltipDate = newDate;
newDate = new Date(newDate).getTime();
newDate = Math.floor(+newDate / 1000);
......@@ -25,4 +32,22 @@ export class PosterDateSelectorComponent {
hasDateSelected() {
return this.tooltipDate && this.tooltipDate !== '';
}
validate(newDate) {
const date = new Date(newDate);
const threeMonths = new Date();
threeMonths.setMonth(threeMonths.getMonth() + 3);
if (date >= threeMonths) {
return "Scheduled date can't be 3 months or more";
}
const fiveMinutes = new Date();
fiveMinutes.setMinutes(fiveMinutes.getMinutes() + 5);
if (date < fiveMinutes) {
return "Scheduled date can't be less than 5 minutes";
}
return true;
}
}
......@@ -173,6 +173,7 @@
<m-poster-date-selector
[date]="blog.time_created"
(dateChange)="onTimeCreatedChange($event)"
(onError)="posterDateSelectorError($event)"
></m-poster-date-selector>
</div>
......
......@@ -239,6 +239,10 @@ export class BlogEdit {
return true;
}
posterDateSelectorError(msg) {
this.error = msg;
}
save() {
if (!this.canSave) return;
......
......@@ -74,7 +74,7 @@ export class ChannelSortedComponent implements OnInit {
protected clientMetaService: ClientMetaService,
@SkipSelf() injector: Injector,
protected cd: ChangeDetectorRef,
public client: Client
public client: Client,
) {
this.clientMetaService
.inherit(injector)
......
......@@ -183,6 +183,7 @@
<m-poster-date-selector
[date]="activity.time_created"
(dateChange)="onTimeCreatedChange($event)"
(onError)="posterDateSelectorError($event)"
></m-poster-date-selector>
<button
class="mdl-button mdl-button--raised mdl-color--blue-grey-100"
......
......@@ -569,4 +569,8 @@ export class Activity implements OnInit {
onTimeCreatedChange(newDate) {
this.activity.time_created = newDate;
}
posterDateSelectorError(msg) {
throw new Error(msg);
}
}
......@@ -99,6 +99,7 @@
<m-poster-date-selector
[date]="meta.time_created"
(dateChange)="onTimeCreatedChange($event)"
(onError)="posterDateSelectorError($event)"
></m-poster-date-selector>
<button
......
......@@ -296,4 +296,8 @@ export class PosterComponent {
onTimeCreatedChange(newDate) {
this.meta.time_created = newDate;
}
posterDateSelectorError(msg) {
this.errorMessage = msg;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment