mirror of
https://github.com/rjNemo/devbook_ts
synced 2026-06-11 21:16:45 +00:00
enable delete credential button
This commit is contained in:
parent
12d52d6ec8
commit
da07929ed3
6 changed files with 49 additions and 7 deletions
|
|
@ -81,6 +81,7 @@ export const dummyDev: Dev = {
|
||||||
'Lorem ipsum, dolor sit amet consectetur adipisicing elit. Blanditiis unde quae vero enim adipisci voluptas magni sapiente reprehenderit error minima.',
|
'Lorem ipsum, dolor sit amet consectetur adipisicing elit. Blanditiis unde quae vero enim adipisci voluptas magni sapiente reprehenderit error minima.',
|
||||||
experiences: [
|
experiences: [
|
||||||
{
|
{
|
||||||
|
id: 1,
|
||||||
company: 'Microsoft',
|
company: 'Microsoft',
|
||||||
from: new Date(2011, 10),
|
from: new Date(2011, 10),
|
||||||
to: 'Current',
|
to: 'Current',
|
||||||
|
|
@ -90,6 +91,7 @@ export const dummyDev: Dev = {
|
||||||
'Lorem ipsum dolor sit, amet consectetur adipisicing elit. Voluptas corrupti rem eius, accusantium ipsum vel eveniet magnam voluptatum? Minus, voluptatum!',
|
'Lorem ipsum dolor sit, amet consectetur adipisicing elit. Voluptas corrupti rem eius, accusantium ipsum vel eveniet magnam voluptatum? Minus, voluptatum!',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: 0,
|
||||||
company: 'Sun Microsystems',
|
company: 'Sun Microsystems',
|
||||||
location: 'USA',
|
location: 'USA',
|
||||||
from: new Date(2004, 10),
|
from: new Date(2004, 10),
|
||||||
|
|
@ -101,6 +103,7 @@ export const dummyDev: Dev = {
|
||||||
],
|
],
|
||||||
educations: [
|
educations: [
|
||||||
{
|
{
|
||||||
|
id: 0,
|
||||||
school: 'University of Washington',
|
school: 'University of Washington',
|
||||||
from: new Date(1993, 9),
|
from: new Date(1993, 9),
|
||||||
to: new Date(1999, 6),
|
to: new Date(1999, 6),
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ const AddEducation: FC<IProps> = ({firebase, educations}) => {
|
||||||
}: FormData): Education => {
|
}: FormData): Education => {
|
||||||
if (current) to = 'Current';
|
if (current) to = 'Current';
|
||||||
const newEdu: Education = {
|
const newEdu: Education = {
|
||||||
|
id: educations.length,
|
||||||
school,
|
school,
|
||||||
degree,
|
degree,
|
||||||
field,
|
field,
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ const AddExperience: FC<IProps> = ({firebase, experiences}) => {
|
||||||
}: FormData): Experience => {
|
}: FormData): Experience => {
|
||||||
if (current) to = 'Current';
|
if (current) to = 'Current';
|
||||||
const newExp: Experience = {
|
const newExp: Experience = {
|
||||||
|
id: experiences.length,
|
||||||
position,
|
position,
|
||||||
company,
|
company,
|
||||||
location,
|
location,
|
||||||
|
|
@ -74,7 +75,6 @@ const AddExperience: FC<IProps> = ({firebase, experiences}) => {
|
||||||
return newExp;
|
return newExp;
|
||||||
};
|
};
|
||||||
const newExp = makeExperience(formData);
|
const newExp = makeExperience(formData);
|
||||||
console.log(JSON.stringify(newExp, null, 4));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
firebase.updateProfile(
|
firebase.updateProfile(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, {FC} from 'react';
|
import React, {FC, MouseEvent} from 'react';
|
||||||
// Redux
|
// Redux
|
||||||
import {WithFirebaseProps} from 'react-redux-firebase';
|
import {WithFirebaseProps} from 'react-redux-firebase';
|
||||||
import {enhance} from '../store/firebase';
|
import {enhance} from '../store/firebase';
|
||||||
|
|
@ -32,6 +32,32 @@ const Dashboard: FC<IProps> = ({
|
||||||
educations,
|
educations,
|
||||||
}) => {
|
}) => {
|
||||||
const logout = () => firebase.logout();
|
const logout = () => firebase.logout();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param id key of the entry to remove
|
||||||
|
* @param entries array of credential educations
|
||||||
|
*/
|
||||||
|
const deleteEduEntry = (id: number, entries: Education[]) => (
|
||||||
|
e: MouseEvent<HTMLButtonElement>,
|
||||||
|
) => {
|
||||||
|
firebase.updateProfile({
|
||||||
|
educations: entries.filter((e: Education) => e.id !== id),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param id key of the entry to remove
|
||||||
|
* @param entries array of credential experiences
|
||||||
|
*/
|
||||||
|
const deleteExpEntry = (id: number, entries: Experience[]) => (
|
||||||
|
e: MouseEvent<HTMLButtonElement>,
|
||||||
|
) => {
|
||||||
|
firebase.updateProfile({
|
||||||
|
experiences: entries.filter((e: Experience) => e.id !== id),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="container">
|
<section className="container">
|
||||||
<Header title="Dashboard" lead={`Welcome ${displayName}`} />
|
<Header title="Dashboard" lead={`Welcome ${displayName}`} />
|
||||||
|
|
@ -58,13 +84,18 @@ const Dashboard: FC<IProps> = ({
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{experiences?.map((exp: Experience, i: number) => (
|
{experiences?.map((exp: Experience) => (
|
||||||
<tr key={i}>
|
<tr key={exp.id}>
|
||||||
<td>{exp.company}</td>
|
<td>{exp.company}</td>
|
||||||
<td className="hide-sm">{exp.position}</td>
|
<td className="hide-sm">{exp.position}</td>
|
||||||
<td className="hide-sm">{getTimePeriod(exp.from, exp.to)}</td>
|
<td className="hide-sm">{getTimePeriod(exp.from, exp.to)}</td>
|
||||||
<td>
|
<td>
|
||||||
<button className="btn btn-danger">Delete</button>
|
<button
|
||||||
|
className="btn btn-danger"
|
||||||
|
onClick={deleteExpEntry(exp.id, experiences)}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
|
|
@ -83,12 +114,17 @@ const Dashboard: FC<IProps> = ({
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{educations?.map((edu: Education, i: number) => (
|
{educations?.map((edu: Education, i: number) => (
|
||||||
<tr key={i}>
|
<tr key={edu.id}>
|
||||||
<td>{edu.school}</td>
|
<td>{edu.school}</td>
|
||||||
<td className="hide-sm">{edu.degree}</td>
|
<td className="hide-sm">{edu.degree}</td>
|
||||||
<td className="hide-sm">{getTimePeriod(edu.from, edu.to)}</td>
|
<td className="hide-sm">{getTimePeriod(edu.from, edu.to)}</td>
|
||||||
<td>
|
<td>
|
||||||
<button className="btn btn-danger">Delete</button>
|
<button
|
||||||
|
className="btn btn-danger"
|
||||||
|
onClick={deleteEduEntry(edu.id, educations)}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import TimePeriod from '../types/TimePeriod';
|
import TimePeriod from '../types/TimePeriod';
|
||||||
|
|
||||||
interface Education {
|
interface Education {
|
||||||
|
id: number;
|
||||||
school: string;
|
school: string;
|
||||||
degree: string;
|
degree: string;
|
||||||
from: TimePeriod;
|
from: TimePeriod;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import TimePeriod from '../types/TimePeriod';
|
import TimePeriod from '../types/TimePeriod';
|
||||||
|
|
||||||
interface Experience {
|
interface Experience {
|
||||||
|
id: number;
|
||||||
company: string;
|
company: string;
|
||||||
from: TimePeriod;
|
from: TimePeriod;
|
||||||
to: TimePeriod;
|
to: TimePeriod;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue