Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/api/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function createGoal(): Promise<Goal | null> {

export async function updateGoal(goalId: string, updatedGoal: Goal): Promise<boolean> {
try {
await axios.put(`${API_ROOT}/api/Goal/${goalId}`, updatedGoal)
(await axios.put(`${API_ROOT}/api/Goal/${goalId}`, updatedGoal))
return true
} catch (error: any) {
return false
Expand Down
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Goal {
targetDate: Date
created: Date
accountId: string
icon: string | undefined
transactionIds: string[]
tagIds: string[]
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/EmojiPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export default function EmojiPicker(props: Props) {
color="primary"
/>
)
}
}
53 changes: 47 additions & 6 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons'
import { faDollarSign, IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { faDollarSign, IconDefinition,faIcons } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date'
import 'date-fns'
import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
import { updateGoal as updateGoalApi } from '../../../api/lib'
import { updateGoal } from '../../../api/lib'
import { Goal } from '../../../api/types'
import { selectGoalsMap, updateGoal as updateGoalRedux } from '../../../store/goalsSlice'
import { useAppDispatch, useAppSelector } from '../../../store/hooks'
import DatePicker from '../../components/DatePicker'
import { Theme } from '../../components/Theme'
import EmojiPicker from '../../components/EmojiPicker'
import { BaseEmoji } from 'emoji-mart'

type Props = { goal: Goal }
export function GoalManager(props: Props) {
Expand All @@ -21,31 +23,48 @@ export function GoalManager(props: Props) {
const [name, setName] = useState<string | null>(null)
const [targetDate, setTargetDate] = useState<Date | null>(null)
const [targetAmount, setTargetAmount] = useState<number | null>(null)
const [Icon, setIcon] = useState<string | undefined>(undefined)
const [emojipickeropen,setEmojipickeropen] = useState<Boolean>(false);

useEffect(() => {
setName(props.goal.name)
setTargetDate(props.goal.targetDate)
setTargetAmount(props.goal.targetAmount)
setIcon(props.goal.icon)
}, [
props.goal.id,
props.goal.name,
props.goal.targetDate,
props.goal.targetAmount,
props.goal.icon,
])

useEffect(() => {
setName(goal.name)
}, [goal.name])

const updateEmojiOnChange = (emoji:BaseEmoji) =>{
const nextEmoji = emoji.native
setIcon(nextEmoji)
const updatedGoal: Goal = {
...props.goal,
icon:nextEmoji
}
dispatch(updateGoalRedux(updatedGoal))
updateGoal(props.goal.id,updatedGoal)
setEmojipickeropen(false)
}

const updateNameOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const nextName = event.target.value
setName(nextName)
const updatedGoal: Goal = {
...props.goal,
name: nextName,
icon:Icon ?? props.goal.icon
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
updateGoal(props.goal.id,updatedGoal)
}

const updateTargetAmountOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -56,9 +75,10 @@ export function GoalManager(props: Props) {
name: name ?? props.goal.name,
targetDate: targetDate ?? props.goal.targetDate,
targetAmount: nextTargetAmount,
icon:Icon ?? props.goal.icon
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
updateGoal(props.goal.id,updatedGoal)
}

const pickDateOnChange = (date: MaterialUiPickersDate) => {
Expand All @@ -69,16 +89,29 @@ export function GoalManager(props: Props) {
name: name ?? props.goal.name,
targetDate: date ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
icon:Icon ?? props.goal.icon
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
updateGoal(props.goal.id,updatedGoal)
}
}

return (
<GoalManagerContainer>
<NameInput value={name ?? ''} onChange={updateNameOnChange} />

<Group>
<Field name="Emoji" icon={faIcons} />
<Value>
{emojipickeropen ? (
<EmojiPicker onClick={updateEmojiOnChange} />
) : (
<GoalIcon onClick={() => setEmojipickeropen(true)}>
{Icon ?? "📌"}
</GoalIcon>
)}
</Value>
</Group>

<Group>
<Field name="Target Date" icon={faCalendarAlt} />
<Value>
Expand Down Expand Up @@ -182,3 +215,11 @@ const StringInput = styled.input`
const Value = styled.div`
margin-left: 2rem;
`

const GoalIcon = styled.div`
font-size: 3rem;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
`
8 changes: 6 additions & 2 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
setType as setTypeRedux
} from '../../../../store/modalSlice'
import { Card } from '../../../components/Card'
import { Icon } from '@material-ui/core'

type Props = { id: string }

Expand All @@ -29,21 +30,24 @@ export default function GoalCard(props: Props) {
<Container key={goal.id} onClick={onClick}>
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
<Icon style={{paddingTop:"1rem", transform: "scale(3.5)", marginTop: "1rem",width:"fit-content",height:"fit-content" }}>{goal.icon}</Icon>
</Container>
)
}

const Container = styled(Card)`
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding-top:1rem;
min-height: 140px;
min-width: 140px;
width: 33%;
cursor: pointer;
margin-left: 2rem;
margin-right: 2rem;
border-radius: 2rem;

align-items: center;
`
const TargetAmount = styled.h2`
Expand All @@ -53,4 +57,4 @@ const TargetAmount = styled.h2`
const TargetDate = styled.h4`
color: rgba(174, 174, 174, 1);
font-size: 1rem;
`
`