Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#216 form instance assign fields and groups #223

Merged
merged 33 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
172ccc5
Imported starter code and fixed typescript bugs
DonnyLe Nov 9, 2024
b1aee16
working on bugs
DonnyLe Nov 11, 2024
f0e0585
Merge branch 'main' into add-text-fields-to-form-template
DonnyLe Nov 11, 2024
b85bea4
pdf viewer working (functionality broken tho)
DonnyLe Nov 12, 2024
8629961
fixed text boxes being behind pdf
DonnyLe Nov 14, 2024
45b5e63
fixed coordinate system
DonnyLe Nov 17, 2024
b603834
completely broken but replaced react-draggable with react-rnd
DonnyLe Nov 19, 2024
b1baa1b
worked on frontend
DonnyLe Nov 20, 2024
f09bae1
broken but fixed some bugs
DonnyLe Nov 20, 2024
a19dc70
multiple boxes + grouping works
DonnyLe Nov 21, 2024
effb4e8
Update AssignInput.tsx
DonnyLe Nov 21, 2024
9cf7152
Made some front-end changes to match figma file
Gayatri-K26 Nov 23, 2024
c946d7e
fixed zooming in and added overflow scroll to page
DonnyLe Nov 27, 2024
14d365c
fixed frontend to match figma more
DonnyLe Nov 28, 2024
35fcf80
fixes to make it better accuracy to figma
DonnyLe Nov 28, 2024
5c920c7
Update AssignInput.tsx
DonnyLe Nov 29, 2024
613c2bf
merge
kaiyangzheng Nov 30, 2024
bd7bd5e
Clean up form editor and make draggable text work
kaiyangzheng Nov 30, 2024
a1457cd
Finish form editor with draggable text
kaiyangzheng Nov 30, 2024
226bd43
fix imports
kaiyangzheng Nov 30, 2024
85dcb66
test
kaiyangzheng Nov 30, 2024
c8ea7ad
refactored to support multiple pages and complete styling + fixed bugs
DonnyLe Dec 1, 2024
7806953
Merge branch 'main' into #216-Form-Instance-Assign-Fields-and-Groups
DonnyLe Dec 2, 2024
fec3613
prettier fix
DonnyLe Dec 2, 2024
ec27296
update name
kaiyangzheng Dec 2, 2024
115ed76
update nav link
kaiyangzheng Dec 2, 2024
4ec01ef
addressed comments
DonnyLe Dec 4, 2024
88c1922
Merge branch 'main' into #216-Form-Instance-Assign-Fields-and-Groups
DonnyLe Dec 4, 2024
725db76
integrated with create template pages
DonnyLe Dec 4, 2024
e77a5b5
persist form fields throughout
kaiyangzheng Dec 4, 2024
e1595ff
Remove console log
kaiyangzheng Dec 4, 2024
6b8014b
done
kaiyangzheng Dec 4, 2024
c14df2f
nvm
kaiyangzheng Dec 4, 2024
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
2 changes: 2 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"pdf-lib": "^1.17.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-draggable": "^4.4.6",
"react-dropzone": "^14.3.5",
"react-icons": "^5.3.0",
"react-pdf": "^7.7.0",
"react-query": "^3.39.3",
"react-rnd": "^10.4.13",
"react-router-dom": "^6.8.1",
"react-scripts": "^5.0.1",
"react-signature-canvas": "^1.0.6",
Expand Down
Binary file modified apps/web/public/test.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/web/src/components/FormInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
UserProfileAvatar,
} from 'apps/web/src/static/icons';
import AssigneeMap from './AvatarMap';
import { useState } from 'react';
import { useRef, useState } from 'react';
import { FormInstanceEntity, FormInstancesService } from '@web/client';
import { useRouter } from 'next/router';
import { useMutation } from '@tanstack/react-query';
Expand Down
19 changes: 17 additions & 2 deletions apps/web/src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SettingsIcon,
PlusIcon,
FormInstanceIcon,
GrayPencilIcon,
} from 'apps/web/src/static/icons';
import { useRouter } from 'next/router';
import Link from 'next/link';
Expand All @@ -30,9 +31,9 @@ const icons = {
pendingActive: <PendingIcon marginRight="2" />,
completed: <CompletedIcon marginRight="2" />,
completedActive: <CompletedIcon marginRight="2" />,
history: <HistoryIcon marginRight="2" />,
settings: <SettingsIcon marginRight="2" />,
formInstance: <FormInstanceIcon marginRight="2" />,
test: <GrayPencilIcon marginRight="2" />,
testActive: <GrayPencilIcon marginRight="2" />,
};
type IconKeys = keyof typeof icons;
/**
Expand Down Expand Up @@ -185,6 +186,20 @@ export const NavBar = ({
<NavItem icon="completed" link="/completed">
Completed
</NavItem>
{process.env.NODE_ENV === 'development' && (
<Box>
<Box
mt="4"
mb="2"
mx="12"
borderBottomWidth="1px"
borderColor="gray.200"
></Box>
<NavItem icon="test" link="/sandbox">
Test
</NavItem>
</Box>
)}
</Box>
);
};
81 changes: 39 additions & 42 deletions apps/web/src/components/createFormTemplate/ReviewBox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Box, Text, Flex } from '@chakra-ui/react';
import { FormEditor, FieldGroups } from './createFormTemplateEditor/FormEditor';
import { useCreateFormTemplate } from '../../context/CreateFormTemplateContext';

/**
* The contents of the white box for the page (step 2) that asks the user for the form's name and
Expand All @@ -12,10 +14,12 @@ export const ReviewBox = ({
formLink,
name,
description,
fieldGroups,
}: {
formLink: string;
name: string;
description: string;
fieldGroups: FieldGroups;
}) => {
const textInputStyle = {
alignSelf: 'stretch',
Expand All @@ -25,36 +29,28 @@ export const ReviewBox = ({
outlineColor: 'transparent',
borderColor: 'transparent',
};
// TODO: these groups should instead be taken from state
const groups: string[] = ['Group 1', 'Group 2', 'Group 3'];

const GroupItem = ({ num }: { num: number }) => {
return num <= groups.length ? (
<Flex gap="10px">
const { formFields } = useCreateFormTemplate();

const GroupItem = ({
num,
color,
border,
}: {
num: number;
color: string;
border: string;
}) => {
return (
<Flex gap="10px" alignItems="center">
<Box
width="24px"
height="24px"
{...(num === 1
? {
border: '1px solid var(--Blue, #1367EA)',
background: '#EEF5FF',
}
: num === 2
? {
border: '1px solid #BD21CA',
background: '#FDEAFF',
}
: num === 3
? {
border: '1px solid #7645E8',
background: '#ECE4FF',
}
: {})}
></Box>
<Text>{groups[num - 1]}</Text>
backgroundColor={color}
border={`1px solid ${border}`}
/>
<Text>Group {num}</Text>
</Flex>
) : (
<></>
);
};

Expand Down Expand Up @@ -85,9 +81,20 @@ export const ReviewBox = ({
<Flex gap="12px" flexDirection="column" width="480px">
<Text fontWeight={600}>Input Field Groups</Text>
</Flex>
<GroupItem num={1} />
<GroupItem num={2} />
<GroupItem num={3} />
{Object.keys(Object.fromEntries(fieldGroups)).map((key, index) => {
const { border, background } = fieldGroups.get(key) as {
border: string;
background: string;
};
return (
<GroupItem
key={index}
num={index + 1}
color={background}
border={border}
/>
);
})}
</Flex>
</Flex>
<Flex
Expand All @@ -104,20 +111,10 @@ export const ReviewBox = ({
>
Preview Only
</Text>
<embed
src={formLink}
type="application/pdf"
width="400px"
height="500px"
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'stretch',
border: '1px solid #E5E5E5',
borderRadius: '8px',
width: '100%',
}}
<FormEditor
formTemplateName={name}
pdfUrl={formLink}
disableEdit={true}
/>
</Flex>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Box, Text } from '@chakra-ui/react';
import { FormEditor } from './FormEditor';

export const AssignInput = () => {
return (
<Box margin="36px" display="flex" flexDirection="column" gap="20px">
<Box>
<Text fontSize="30px" fontWeight="700" lineHeight="38px">
Create form template
</Text>
<Text
fontSize="19px"
color="#4B4C4F"
fontFamily="Hanken Grotesk"
fontWeight="500"
lineHeight="26px"
wordBreak="break-word"
>
Select an assignee group and drag to add input fields for each
</Text>
</Box>
<FormEditor
formTemplateName="Authorization Form"
pdfUrl={'http://localhost:3002/test.pdf'}
disableEdit={false}
/>
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Draggable, { DraggableEventHandler } from 'react-draggable';

export default function DraggableSignature({
onEnd,
onSet,
onCancel,
url,
}: {
onEnd: DraggableEventHandler;
onSet: () => void;
onCancel: () => void;
url: string;
}) {
const styles = {
container: {
Position: 'absolute',
zIndex: 100000,
border: `2px solid gray`,
},
controls: {
Position: 'absolute',
right: 0,
display: 'inline-block',
backgroundColor: 'white',
},
smallButton: {
display: 'inline-block',
cursor: 'pointer',
padding: 4,
},
};
return (
<Draggable onStop={onEnd}>
<div style={styles.container}>
<div style={styles.controls}>
<div style={styles.smallButton} onClick={onSet}>
Set{' '}
</div>
<div style={styles.smallButton} onClick={onCancel}>
Cancel
</div>
</div>
</div>
</Draggable>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Rnd, RndResizeCallback } from 'react-rnd';
import { DraggableEventHandler } from 'react-draggable';
import { TextFieldPosition } from './FormEditor';
import { FaTimes } from 'react-icons/fa';

export default function DraggableText({
onStop,
onResizeStop,
color,
onRemove,
currentPosition,
disableEdit,
}: {
onStop: DraggableEventHandler;
onResizeStop: RndResizeCallback;
initialText: string | null;
color: string;
onRemove: () => void;
currentPosition: TextFieldPosition;
disableEdit: boolean;
}) {
return (
<Rnd
DonnyLe marked this conversation as resolved.
Show resolved Hide resolved
bounds="parent"
position={{ x: currentPosition.x, y: currentPosition.y }}
size={{ height: currentPosition.height, width: currentPosition.width }}
DonnyLe marked this conversation as resolved.
Show resolved Hide resolved
minWidth="50px"
minHeight="40px"
style={{
position: 'absolute',
zIndex: 100000,
background: `${color}`,
opacity: '10px',
border: `solid 1px grey`,
padding: 4,
}}
onDragStop={onStop}
onResizeStop={onResizeStop}
disableDragging={disableEdit}
>
<div
style={{
position: 'absolute',
display: 'inline-block',
borderRadius: 4,
}}
>
{!disableEdit && (
<div
style={{
display: 'inline-block',
cursor: 'pointer',
padding: 4,
}}
onClick={onRemove}
>
<FaTimes color={'#ef6565'} />
</div>
)}
</div>
</Rnd>
);
}
Loading
Loading