11import {
22 Stack ,
33 Typography ,
4- Grid ,
54 Container ,
65 TextareaAutosize ,
6+ Box ,
77} from "@mui/material" ;
88import { format } from "date-fns" ;
99import { useState } from "react" ;
1010
11+ import Chip from "@/components/design_system/chip/Chip" ;
1112import Button from "@/components/design_system/button/Button" ;
1213import { trpc } from "@/client/lib/trpc" ;
1314import $GoalPage from "@/styles/GoalPage.module.css" ;
15+
1416type GoalHeaderProps = {
1517 goalId : string ;
1618 name : string ;
@@ -29,6 +31,7 @@ export const GoalHeader = ({
2931 const [ editGoal , setEditGoal ] = useState ( false ) ;
3032 const [ editGoalInput , setEditGoalInput ] = useState ( "" ) ;
3133 const utils = trpc . useContext ( ) ;
34+
3235 const showEditGoal = ( ) => {
3336 setEditGoal ( true ) ;
3437 setEditGoalInput ( description || "" ) ;
@@ -53,80 +56,120 @@ export const GoalHeader = ({
5356 setEditGoal ( false ) ;
5457 setEditGoalInput ( "" ) ;
5558 } ;
59+
5660 return (
5761 < Container className = { $GoalPage . goalDescriptionContainer } >
58- < Grid container justifyContent = "space-between" >
59- < Stack spacing = { 2 } sx = { { marginBottom : "28px" } } >
60- < Stack direction = "row" alignItems = "center" spacing = { 1 } >
61- < Typography variant = "h3" color = "var(--primary-40)" >
62- { name }
63- </ Typography >
64- < Typography variant = "h3" > |</ Typography >
65- < Typography variant = "h3" color = "#788591" >
66- Added: { format ( new Date ( createdAt ) , "MM/dd/yyyy" ) }
67- </ Typography >
62+ < Box
63+ sx = { {
64+ display : "flex" ,
65+ flexDirection : "column" ,
66+ gap : 2 ,
67+ } }
68+ >
69+ < Box
70+ sx = { {
71+ display : "flex" ,
72+ flexDirection : { xs : "column" , md : "row" } ,
73+ justifyContent : "space-between" ,
74+ alignItems : { xs : "flex-start" , md : "center" } ,
75+ gap : 2 ,
76+ } }
77+ >
78+ < Stack
79+ direction = { { xs : "column" , md : "row" } }
80+ spacing = { 1.5 }
81+ alignItems = "flex-start"
82+ sx = { { flexShrink : 0 } }
83+ >
84+ < Chip label = { name } variant = "target" />
85+ < Chip
86+ label = { `Created on: ${ format ( new Date ( createdAt ) , "MMM, dd, yyyy" ) } ` }
87+ variant = "calendar"
88+ />
6889 </ Stack >
69- </ Stack >
70- { editable && (
71- < Grid
90+ { editable && (
91+ < Box
92+ sx = { {
93+ display : "flex" ,
94+ flexDirection : { xs : "column" , sm : "row" } ,
95+ gap : 1 ,
96+ width : { xs : "100%" , md : "auto" } ,
97+ } }
98+ >
99+ { ! editGoal && (
100+ < Box sx = { { display : "flex" , justifyContent : "right" } } >
101+ < Button
102+ variant = "tertiary"
103+ onClick = { showEditGoal }
104+ sx = { { width : { md : "auto" } } }
105+ >
106+ Edit goal
107+ </ Button >
108+ < Button
109+ variant = "secondary"
110+ onClick = { ( ) => alert ( "to be implemented" ) }
111+ sx = { { width : { md : "auto" } } }
112+ >
113+ View all goals
114+ </ Button >
115+ </ Box >
116+ ) }
117+ { editGoal && (
118+ < >
119+ < Button
120+ variant = "tertiary"
121+ onClick = { cancelEditGoal }
122+ sx = { { width : { xs : "100%" , md : "auto" } } }
123+ >
124+ Cancel
125+ </ Button >
126+ < Button
127+ onClick = { submitEditGoal }
128+ sx = { { width : { xs : "100%" , md : "auto" } } }
129+ >
130+ Save
131+ </ Button >
132+ </ >
133+ ) }
134+ </ Box >
135+ ) }
136+ </ Box >
137+ { editGoal && editable ? (
138+ < TextareaAutosize
139+ className = { $GoalPage . editGoalFormTextArea }
140+ value = { editGoalInput }
141+ name = "description"
142+ onChange = { ( e ) => {
143+ setEditGoalInput ( e . target . value ) ;
144+ } }
145+ style = { {
146+ width : "100%" ,
147+ padding : "24px" ,
148+ fontSize : "0.95rem" ,
149+ lineHeight : "1.6" ,
150+ borderRadius : "8px" ,
151+ border : "1px solid var(--outline)" ,
152+ fontFamily : "inherit" ,
153+ minHeight : "100px" ,
154+ backgroundColor : "var(--on-primary)" ,
155+ } }
156+ />
157+ ) : (
158+ < Typography
159+ variant = "body1"
72160 sx = { {
73- display : "flex " ,
74- flexDirection : "start " ,
75- justifyContent : "start " ,
76- justifyItems : "start " ,
77- height : "100%" ,
78- pb : 1 ,
161+ fontSize : "16px " ,
162+ lineHeight : "150% " ,
163+ color : "var(--on-background) " ,
164+ fontFamily : "var(--inter) " ,
165+ fontWeight : 400 ,
166+ letterSpacing : "0%" ,
79167 } }
80- item
81168 >
82- { ! editGoal && (
83- < >
84- < Button
85- variant = "tertiary"
86- onClick = { showEditGoal }
87- sx = { {
88- margin : "auto" ,
89- } }
90- >
91- Edit Goal
92- </ Button >
93- < Button
94- variant = "secondary"
95- onClick = { ( ) => alert ( "to be implemented" ) }
96- >
97- View all goals
98- </ Button >
99- </ >
100- ) }
101- { editGoal && (
102- < >
103- < Button
104- variant = "tertiary"
105- form = "editGoalForm"
106- onClick = { cancelEditGoal }
107- >
108- Cancel
109- </ Button >
110- < Button form = "editGoalForm" onClick = { submitEditGoal } >
111- Save
112- </ Button >
113- </ >
114- ) }
115- </ Grid >
169+ { description }
170+ </ Typography >
116171 ) }
117- </ Grid >
118- { editGoal && editable && (
119- < TextareaAutosize
120- className = { $GoalPage . editGoalFormTextArea }
121- value = { editGoalInput }
122- name = "description"
123- onChange = { ( e ) => {
124- setEditGoalInput ( e . target . value ) ;
125- } }
126- />
127- ) }
128-
129- { ! editGoal && < Typography variant = "body1" > { description } </ Typography > }
172+ </ Box >
130173 </ Container >
131174 ) ;
132175} ;
0 commit comments