add Dev class, IDev interface, remove blankDev and getDescription method

This commit is contained in:
Ruidy Nemausat 2020-05-17 13:14:06 +02:00
parent bdcee6d6f9
commit fa353664fb
2 changed files with 59 additions and 28 deletions

View file

@ -5,7 +5,7 @@ import Repo from '../types/Repo';
/** Shorter dev interface */ /** Shorter dev interface */
export interface DevSummary { export interface DevSummary {
id: string; id?: string;
displayName: string; displayName: string;
avatarUrl: string; avatarUrl: string;
description: string; description: string;
@ -16,7 +16,7 @@ export interface DevSummary {
/** Full developer profile information. /** Full developer profile information.
* @extends DevSummary to avoid duplication * @extends DevSummary to avoid duplication
*/ */
interface Dev extends DevSummary { interface IDev extends DevSummary {
isActive: boolean; isActive: boolean;
bio: string; bio: string;
status: string; status: string;
@ -27,23 +27,25 @@ interface Dev extends DevSummary {
repos: Repo[]; repos: Repo[];
} }
/** create profile tagline */ /** class implementing IDev.
export const getDescription = (status: string, company: string) => * No constructor is provided.
`${status} at ${company}`; * new Dev() returns a placeholder used when initializing a new profile.
/** blank Dev serve as placeholder when initializing a new profile
* id is not specified to not overwrite document uid. * id is not specified to not overwrite document uid.
*/ */
export const blankDev = { export class Dev implements IDev {
isActive: true, id?: string;
displayName: '', isActive = true;
status: 'Developer', displayName = '';
company: '', status = 'Developer';
avatarUrl: '', company = '';
description: '', avatarUrl = '';
location: '', /** create profile tagline */
skills: [], get description(): string {
links: { return `${this.status} at ${this.company}`;
}
location = '';
skills: string[] = [];
links: Links = {
website: '', website: '',
instagram: '', instagram: '',
facebook: '', facebook: '',
@ -51,17 +53,46 @@ export const blankDev = {
twitter: '', twitter: '',
github: '', github: '',
youtube: '', youtube: '',
}, };
bio: '', bio = '';
experiences: [], experiences: Experience[] = [];
educations: [], educations: Education[] = [];
repos: [], repos: Repo[] = [];
}; }
//
// export const getDescription = (status: string, company: string) =>
// `${status} at ${company}`;
/**
*/
// export const blankDev = {
// isActive: true,
// displayName: '',
// status: 'Developer',
// company: '',
// avatarUrl: '',
// description: '',
// location: '',
// skills: [],
// links: {
// website: '',
// instagram: '',
// facebook: '',
// linkedin: '',
// twitter: '',
// github: '',
// youtube: '',
// },
// bio: '',
// experiences: [],
// educations: [],
// repos: [],
// };
/** /**
* sample Dev for development and tests * sample Dev for development and tests
*/ */
export const dummyDev: Dev = { export const dummyDev: IDev = {
id: '0', id: '0',
isActive: true, isActive: true,
displayName: 'John Doe', displayName: 'John Doe',
@ -170,4 +201,4 @@ export const developers: DevSummary[] = [
}, },
]; ];
export default Dev; export default IDev;

View file

@ -12,7 +12,7 @@ import Alert from '../components/Alert';
import Header from '../components/Header'; import Header from '../components/Header';
// Form // Form
import useForm from '../hooks'; import useForm from '../hooks';
import Dev, {blankDev} from '../models/Dev'; import {Dev} from '../models/Dev';
// extends withFirebaseProps type to ad profile info // extends withFirebaseProps type to ad profile info
interface IProps extends Dev, WithFirebaseProps<User> { interface IProps extends Dev, WithFirebaseProps<User> {
@ -57,7 +57,7 @@ const SignUp: FC<IProps> = ({firebase, isEmpty, isLoaded, isActive}) => {
firebase firebase
.createUser({email, password}, newUser(name, email)) .createUser({email, password}, newUser(name, email))
.then(() => { .then(() => {
firebase.updateProfile(blankDev, {useSet: true, merge: true}); firebase.updateProfile(new Dev(), {useSet: true, merge: true});
resetForm(); resetForm();
}) })
.catch(err => setError(err)); .catch(err => setError(err));
@ -82,7 +82,7 @@ const SignUp: FC<IProps> = ({firebase, isEmpty, isLoaded, isActive}) => {
) )
.then(() => { .then(() => {
if (!exists) if (!exists)
firebase.updateProfile(blankDev, {useSet: true, merge: true}); firebase.updateProfile(new Dev(), {useSet: true, merge: true});
}); });
}) })
.catch(err => setError(err)); .catch(err => setError(err));