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
3 changes: 2 additions & 1 deletion package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"@material-ui/core": "^4.12.4",
"@material-ui/pickers": "^3.3.10",
"@reduxjs/toolkit": "^1.5.1",
"@types/emoji-mart": "^3.0.5",
"@types/node": "^17.0.41",
"@types/react": "^16.9.0",
"@types/react-redux": "^7.1.7",
Expand Down Expand Up @@ -59,4 +58,4 @@
"@types/react-dom": "^18.0.5",
"@types/styled-components": "^5.1.25"
}
}
}
2 changes: 1 addition & 1 deletion src/api/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import { user } from '../data/user'
import { Goal, Transaction, User } from './types'

export const API_ROOT = 'https://fencer-commbank.azurewebsites.net'
export const API_ROOT = 'http://localhost:5203'

export async function getUser(): Promise<User | null> {
try {
Expand Down
9 changes: 1 addition & 8 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface Account {
applicationId: string
transactionIds: string[]
}

export interface Application {
id: string
created: Date
Expand All @@ -16,7 +15,6 @@ export interface Application {
applicationStatus: ApplicationStatus
userId: string
}

export interface Goal {
id: string
name: string
Expand All @@ -27,13 +25,12 @@ export interface Goal {
accountId: string
transactionIds: string[]
tagIds: string[]
icon?: string
}

export interface Tag {
id: string
name: string
}

export interface Transaction {
id: string
transactionType: 'Debit' | 'Credit' | 'Transfer'
Expand All @@ -43,26 +40,22 @@ export interface Transaction {
description: string
tagIds: string[]
}

export interface User {
id: string
name: string
email: string
applicationIds: string[]
}

export enum AccountType {
GoalSaver,
NetBankSaver,
}

export enum ApplicationStatus {
Received,
Assigned,
UnderReview,
Approved,
Rejected,
}

export type ModalContent = Goal
export type ModalType = 'Goal'
78 changes: 78 additions & 0 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons'
import { faDollarSign, IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date'
import 'emoji-mart/css/emoji-mart.css'
import { Picker, EmojiData } from 'emoji-mart'
import 'date-fns'
import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
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 | undefined>(undefined)
const [pickerOpen, setPickerOpen] = 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(() => {
Expand Down Expand Up @@ -75,10 +81,43 @@ export function GoalManager(props: Props) {
}
}

const onEmojiSelect = (emoji: EmojiData) => {
if ('native' in emoji) {
const selectedIcon = emoji.native
setIcon(selectedIcon)
setPickerOpen(false)
const updatedGoal: Goal = {
...props.goal,
name: name ?? props.goal.name,
icon: selectedIcon,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}
}

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

<GoalIconContainer shouldShow={!!icon}>
{icon && <GoalIcon>{icon}</GoalIcon>}
<AddIconButtonContainer shouldShow={!icon}>
<AddIconButton onClick={() => setPickerOpen(!pickerOpen)}>
{icon ? 'Change Icon' : '+ Add Icon'}
</AddIconButton>
</AddIconButtonContainer>
{icon && (
<AddIconButton onClick={() => setPickerOpen(!pickerOpen)}>
Change Icon
</AddIconButton>
)}
</GoalIconContainer>

<EmojiPickerContainer isOpen={pickerOpen} hasIcon={!!icon}>
{pickerOpen && <Picker onSelect={onEmojiSelect} />}
</EmojiPickerContainer>

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

const GoalIconContainer = styled.div<GoalIconContainerProps>`
display: flex;
flex-direction: row;
align-items: center;
margin-top: 1rem;
margin-bottom: 1rem;
`

const GoalIcon = styled.span`
font-size: 3rem;
margin-right: 1rem;
`

const AddIconButtonContainer = styled.div<AddIconButtonContainerProps>`
display: ${({ shouldShow }) => (shouldShow ? 'flex' : 'none')};
`

const AddIconButton = styled.button`
background: none;
border: 2px solid rgba(174, 174, 174, 1);
border-radius: 8px;
padding: 0.5rem 1rem;
font-size: 1.2rem;
cursor: pointer;
color: rgba(174, 174, 174, 1);
&:hover {
border-color: #007bff;
color: #007bff;
}
`

const EmojiPickerContainer = styled.div<EmojiPickerContainerProps>`
display: ${({ isOpen }) => (isOpen ? 'flex' : 'none')};
position: absolute;
top: ${({ hasIcon }) => (hasIcon ? '12rem' : '10rem')};
left: 0;
z-index: 100;
`