Last active
January 10, 2019 10:55
-
-
Save AntonGorelov/40d8bfd79b1afe24aef625daa2186e47 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { Injectable } from '@angular/core'; | |
import { BehaviorSubject, Observable } from 'rxjs'; | |
import { | |
ICompany, | |
ISchool, | |
IRegion, | |
IOrganization, | |
ICountry, | |
} from '@lib/models'; | |
import { MODE } from './company-modes'; | |
@Injectable() | |
export class CompanyProfileService { | |
private _mode$ = new BehaviorSubject<string>('show'); | |
private _draftCompany$ = new BehaviorSubject<ICompany>(undefined); | |
constructor() {} | |
/** | |
* Get value of current mode: 'show', 'preview', 'edit'. | |
*/ | |
public get mode$(): Observable<string> { | |
return this._mode$.asObservable(); | |
} | |
/** | |
* Get value of current company. | |
*/ | |
public get draftCompany$(): Observable<ICompany> { | |
return this._draftCompany$.asObservable(); | |
} | |
public getDraftCompanyValue(): ICompany { | |
return this._draftCompany$.value; | |
} | |
public setDraftCompany(company: ICompany) { | |
this._draftCompany$.next(company); | |
} | |
public resetDraftCompany() { | |
this._draftCompany$.next(this.createEmptyCompany()); | |
} | |
public setMode(mode: string) { | |
this._mode$.next(mode); | |
} | |
public isShowMode() { | |
return this._mode$.value === MODE.show; | |
} | |
public isEditMode() { | |
return this._mode$.value === MODE.edit; | |
} | |
public isNewMode() { | |
return this._mode$.value === MODE.new; | |
} | |
/** | |
* Check mode of the company. | |
* | |
* @returns{boolean} Set true if the company is in edit mode. | |
*/ | |
public isEditable() { | |
return this.isEditMode() || this.isNewMode(); | |
} | |
public createEmptyCompany(): ICompany { | |
return { | |
id: null, | |
logo: '', | |
coverImage: '', | |
name: '', | |
school: <ISchool>{}, | |
region: <IRegion>{}, | |
categories: [], | |
description: '', | |
aboutUs: '', | |
organization: <IOrganization>{}, | |
active: false, | |
teamMembers: [], | |
products: [], | |
country: <ICountry>{}, | |
stripeConnected: false, | |
hasProducts: false, | |
activationPending: false, | |
activationRequestSentAt: null, | |
referenceNumber: null, | |
productCount: null, | |
googleAnalyticsId: '', | |
membershipRequests: [], | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment