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
38 changes: 38 additions & 0 deletions GoalControllerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public class GoalControllerTests
{
private readonly FakeCollections collections;

public GoalControllerTests()
{
collections = new();
}

// ...

[Fact]
public async void GetForUser()
{
// Arrange
var goals = collections.GetGoals();
var users = collections.GetUsers();
IGoalsService goalsService = new FakeGoalsService(goals, goals[0]);
IUsersService usersService = new FakeUsersService(users, users[0]);
GoalController controller = new(goalsService, usersService);

// Act
var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext();
controller.ControllerContext.HttpContext = httpContext;
var result = await controller.GetForUser(goals[0].UserId!);

// Assert
Assert.NotNull(result);

var index = 0;
foreach (Goal goal in result!)
{
Assert.IsAssignableFrom<Goal>(goal);
Assert.Equal(goals[0].UserId, goal.UserId);
index++;
}
}
}
12 changes: 12 additions & 0 deletions put_request.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from 'axios'
import { Goal } from './types'
import { API_ROOT } from './lib' // Assuming API_ROOT is defined in lib.ts

export async function updateGoal(goalId: string, updatedGoal: Goal): Promise<boolean> {
try {
await axios.put(`${API_ROOT}/api/Goal/${goalId}`, updatedGoal)
return true
} catch (error: any) {
return false
}
}
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Goal {
accountId: string
transactionIds: string[]
tagIds: string[]
icon: string | null
}

export interface Tag {
Expand Down
65 changes: 64 additions & 1 deletion src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons'
import { faDollarSign, IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { faDollarSign, faPlus, IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date'
import 'date-fns'
import { Picker } from 'emoji-mart'
import 'emoji-mart/css/emoji-mart.css'
import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
import { updateGoal as updateGoalApi } from '../../../api/lib'
Expand All @@ -21,16 +23,20 @@ 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 | null>(null)
const [showPicker, setShowPicker] = useState(false)

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

useEffect(() => {
Expand All @@ -43,6 +49,7 @@ export function GoalManager(props: Props) {
const updatedGoal: Goal = {
...props.goal,
name: nextName,
icon: icon ?? props.goal.icon,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
Expand All @@ -56,6 +63,7 @@ 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)
Expand All @@ -69,14 +77,43 @@ 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)
}
}

const pickEmojiOnClick = () => (emoji: any, event?: any) => {
setIcon(emoji.native)
setShowPicker(false)
const updatedGoal: Goal = {
...props.goal,
icon: emoji.native ?? props.goal.icon,
name: name ?? props.goal.name,
targetDate: targetDate ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}

return (
<GoalManagerContainer>
{icon ? (
<GoalIconContainer shouldShow={true} onClick={() => setShowPicker(!showPicker)}>
{icon}
</GoalIconContainer>
) : (
<AddIconButtonContainer shouldShow={true} onClick={() => setShowPicker(!showPicker)}>
<FontAwesomeIcon icon={faPlus} size="2x" />
</AddIconButtonContainer>
)}

<EmojiPickerContainer isOpen={showPicker} hasIcon={!!icon}>
<Picker onSelect={pickEmojiOnClick()} theme="dark" />
</EmojiPickerContainer>

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

<Group>
Expand Down Expand Up @@ -139,6 +176,32 @@ const Group = styled.div`
margin-top: 1.25rem;
margin-bottom: 1.25rem;
`

const AddIconButtonContainer = styled.div<AddIconButtonContainerProps>`
display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
width: 4rem;
height: 4rem;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.1);
align-items: center;
justify-content: center;
cursor: pointer;
margin-bottom: 1rem;
`

const GoalIconContainer = styled.div<GoalIconContainerProps>`
display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
font-size: 4rem;
cursor: pointer;
margin-bottom: 1rem;
`

const EmojiPickerContainer = styled.div<EmojiPickerContainerProps>`
display: ${(props) => (props.isOpen ? 'block' : 'none')};
position: absolute;
top: ${(props) => (props.hasIcon ? '5rem' : '5rem')};
z-index: 100;
`
const NameInput = styled.input`
display: flex;
background-color: transparent;
Expand Down
6 changes: 6 additions & 0 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function GoalCard(props: Props) {

return (
<Container key={goal.id} onClick={onClick}>
{goal.icon && <Icon>{goal.icon}</Icon>}
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
</Container>
Expand Down Expand Up @@ -54,3 +55,8 @@ const TargetDate = styled.h4`
color: rgba(174, 174, 174, 1);
font-size: 1rem;
`

const Icon = styled.span`
font-size: 3rem;
margin-bottom: 0.5rem;
`