-
Notifications
You must be signed in to change notification settings - Fork 60
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
[SFT-1608]: Write integration for Form Monitor #1686
Open
gustavs-gutmanis
wants to merge
22
commits into
v5
Choose a base branch
from
feat/SFT-1608-form-monitor
base: v5
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,471
−23
Open
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
759439b
feat(SFT-1608): adding initial Form Monitor files
gustavs-gutmanis 5754088
feat(SFT-1608): add form monitor integration
gustavs-gutmanis 97236d7
chore: updating artifacts
gustavs-gutmanis 6cf0010
feat(SFT-1608): adding form manifest
gustavs-gutmanis fc9732a
feat(SFT-1608): sending URL with manifest
gustavs-gutmanis 9881a73
feat(SFT-1608): adding captcha bypass
gustavs-gutmanis 7d31d17
feat(SFT-1608): add hidden submission support for form monitor checking
gustavs-gutmanis 6189c60
feat(SFT-1608): adding initial Form Monitor files
gustavs-gutmanis 8afd700
feat(SFT-1608): add form monitor integration
gustavs-gutmanis 621521f
chore: updating artifacts
gustavs-gutmanis c2ebc7d
feat(SFT-1608): adding form manifest
gustavs-gutmanis edb32b4
feat(SFT-1608): sending URL with manifest
gustavs-gutmanis 29c6750
feat(SFT-1608): adding captcha bypass
gustavs-gutmanis d0d1682
feat(SFT-1608): add hidden submission support for form monitor checking
gustavs-gutmanis 58d0cf0
Merge remote-tracking branch 'origin/feat/SFT-1608-form-monitor' into…
gustavs-gutmanis 9064487
feat(SFT-1608): disabling integrations for form monitor requests
gustavs-gutmanis a8171a9
feat(SFT-1611): override all emails when submitting through FM
gustavs-gutmanis 9e5b515
feat(SFT-1613): build UI for Form Monitor
gustavs-gutmanis 9c76bfa
Merge branch 'v5' into feat/SFT-1608-form-monitor
gustavs-gutmanis b2d98cd
Merge branch 'v5' of https://github.com/solspace/craft-freeform into …
kjmartens 9a5ad0f
Merge branch 'v5' of https://github.com/solspace/craft-freeform into …
kjmartens f089b64
feat(SFT-1608): add submission ack call
gustavs-gutmanis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/client/src/app/pages/form-monitor/form-monitor.empty.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { EmptyBlock } from '@components/empty-block/empty-block'; | ||
import translate from '@ff-client/utils/translations'; | ||
|
||
import { FormMonitorWrapper } from './form-monitor.styles'; | ||
|
||
export const FMEmptyTests: React.FC = () => { | ||
return ( | ||
<FormMonitorWrapper> | ||
<EmptyBlock lite title={translate('No form tests found')} /> | ||
</FormMonitorWrapper> | ||
); | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/client/src/app/pages/form-monitor/form-monitor.forms.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react'; | ||
|
||
export const FMFormsList: React.FC = () => { | ||
return <div></div>; | ||
}; |
41 changes: 41 additions & 0 deletions
41
packages/client/src/app/pages/form-monitor/form-monitor.queries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { UseQueryResult } from '@tanstack/react-query'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import axios from 'axios'; | ||
|
||
export const QKFormMonitor = { | ||
forms: ['form-monitor', 'forms'], | ||
formTests: (id?: number) => | ||
id !== undefined | ||
? [...QKFormMonitor.forms, id, 'form-tests'] | ||
: [...QKFormMonitor.forms, 'tests'], | ||
} as const; | ||
|
||
export const useFMForms = (): UseQueryResult<number[]> => { | ||
return useQuery(QKFormMonitor.forms, () => | ||
axios.get<number[]>('/api/form-monitor/forms').then((res) => res.data) | ||
); | ||
}; | ||
|
||
type FMTest = { | ||
id: string; | ||
formId: number; | ||
dateAttempted: string; | ||
dateCompleted: string; | ||
status: 'success' | 'fail'; | ||
response: null | string; | ||
responseCode: number; | ||
}; | ||
|
||
type FMTestsResponse = FMTest[]; | ||
|
||
export const useFMFormTestsQuery = ( | ||
id?: number | ||
): UseQueryResult<FMTestsResponse> => { | ||
const url = id | ||
? `/api/form-monitor/forms/${id}/tests` | ||
: '/api/form-monitor/tests'; | ||
|
||
return useQuery(QKFormMonitor.formTests(id), () => | ||
axios.get<FMTestsResponse>(url).then((res) => res.data) | ||
); | ||
}; |
69 changes: 69 additions & 0 deletions
69
packages/client/src/app/pages/form-monitor/form-monitor.styles.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { PropsWithChildren } from 'react'; | ||
import React from 'react'; | ||
import { Breadcrumb } from '@components/breadcrumbs/breadcrumbs'; | ||
import { ContentContainer } from '@components/layout/blocks/content-container'; | ||
import { HeaderContainer } from '@components/layout/blocks/header-container'; | ||
import { colors } from '@ff-client/styles/variables'; | ||
import translate from '@ff-client/utils/translations'; | ||
import styled from 'styled-components'; | ||
|
||
export const FormMonitorWrapper: React.FC<PropsWithChildren> = ({ | ||
children, | ||
}) => { | ||
return ( | ||
<div> | ||
<Breadcrumb | ||
id="form-monitor" | ||
label={translate('Form Monitor')} | ||
url="/form-monitor" | ||
/> | ||
|
||
<HeaderContainer>{translate('Form Monitor')}</HeaderContainer> | ||
|
||
<div id="main-content"> | ||
<ContentContainer> | ||
<div id="content">{children}</div> | ||
</ContentContainer> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const TestBlock = styled.div` | ||
display: flex; | ||
gap: 5px; | ||
`; | ||
|
||
export const TestTable = styled.table` | ||
thead th { | ||
white-space: nowrap; | ||
} | ||
|
||
tbody td { | ||
vertical-align: top; | ||
|
||
&.no-break { | ||
white-space: nowrap; | ||
} | ||
} | ||
|
||
.status-col { | ||
display: flex; | ||
gap: 5px; | ||
align-items: center; | ||
} | ||
`; | ||
|
||
export const StatusBadge = styled.div` | ||
padding: 1px 5px; | ||
|
||
border-radius: 5px; | ||
|
||
font-size: 10px; | ||
color: ${colors.white}; | ||
background-color: ${colors.teal500}; | ||
|
||
&.status-fail { | ||
background-color: ${colors.red500}; | ||
} | ||
`; |
92 changes: 92 additions & 0 deletions
92
packages/client/src/app/pages/form-monitor/form-monitor.tests.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React from 'react'; | ||
import { Link, useParams } from 'react-router-dom'; | ||
import { useSidebarSelect } from '@ff-client/hooks/use-sidebar-select'; | ||
import { useQueryFormsWithStats } from '@ff-client/queries/forms'; | ||
import { scrollBar } from '@ff-client/styles/mixins'; | ||
import { borderRadius, colors, spacings } from '@ff-client/styles/variables'; | ||
import translate from '@ff-client/utils/translations'; | ||
import { format, parseISO } from 'date-fns'; | ||
import styled from 'styled-components'; | ||
|
||
import { FMEmptyTests } from './form-monitor.empty'; | ||
import { useFMFormTestsQuery } from './form-monitor.queries'; | ||
import { | ||
FormMonitorWrapper, | ||
StatusBadge, | ||
TestTable, | ||
} from './form-monitor.styles'; | ||
|
||
const CodeBlock = styled.div` | ||
position: relative; | ||
|
||
padding: ${spacings.sm} ${spacings.md}; | ||
|
||
font-family: monospace; | ||
|
||
background: ${colors.gray050}; | ||
border: 1px solid ${colors.hairline}; | ||
border-radius: ${borderRadius.lg}; | ||
|
||
max-height: 60px; | ||
overflow-y: auto; | ||
|
||
${scrollBar}; | ||
`; | ||
|
||
export const FMTests: React.FC = () => { | ||
const { formId } = useParams(); | ||
|
||
const { data: forms } = useQueryFormsWithStats(); | ||
const { data, isFetching } = useFMFormTestsQuery(Number(formId)); | ||
|
||
useSidebarSelect(5); | ||
|
||
return ( | ||
<FormMonitorWrapper> | ||
{data === undefined && isFetching && <div>{translate('Loading...')}</div>} | ||
{data && data.length === 0 && <FMEmptyTests />} | ||
{data !== undefined && data.length > 0 && ( | ||
<TestTable> | ||
<thead> | ||
<tr> | ||
<th>{translate('Test ID')}</th> | ||
<th>{translate('Date')}</th> | ||
<th>{translate('Form')}</th> | ||
<th>{translate('Status')}</th> | ||
<th>{translate('Response')}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{data.map((test) => { | ||
const form = forms.find((form) => form.id === test.formId); | ||
if (!form) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<tr key={test.id}> | ||
<td className="no-break">#{test.id}</td> | ||
<td className="no-break" title={test.dateCompleted}> | ||
{format(parseISO(test.dateCompleted), 'do MMM yyyy')} | ||
</td> | ||
<td> | ||
<Link to={`/forms/${form.id}`}>{form.name}</Link> | ||
</td> | ||
<td className="status-col no-break"> | ||
<StatusBadge className={`status-${test.status}`}> | ||
{test.responseCode} | ||
</StatusBadge> | ||
<div>{test.status}</div> | ||
</td> | ||
<td className="code" title={test.response}> | ||
{!!test.response && <CodeBlock>{test.response}</CodeBlock>} | ||
</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</TestTable> | ||
)} | ||
</FormMonitorWrapper> | ||
); | ||
}; |
62 changes: 62 additions & 0 deletions
62
packages/client/src/app/pages/form-monitor/form-monitor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-disable react/display-name */ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { EmptyBlock } from '@components/empty-block/empty-block'; | ||
import config, { Edition } from '@config/freeform/freeform.config'; | ||
import { useSidebarSelect } from '@ff-client/hooks/use-sidebar-select'; | ||
import { useQueryFormsWithStats } from '@ff-client/queries/forms'; | ||
import translate from '@ff-client/utils/translations'; | ||
|
||
import { useFMForms } from './form-monitor.queries'; | ||
import { FormMonitorWrapper } from './form-monitor.styles'; | ||
|
||
export const FormMonitor: React.FC = () => { | ||
const isPro = config.editions.isAtLeast(Edition.Pro); | ||
useSidebarSelect(5); | ||
|
||
const { data: forms, isFetching: isFetchingForms } = useQueryFormsWithStats(); | ||
const { data: formIds, isFetching: isFetchingFormids } = useFMForms(); | ||
|
||
const isLoading = | ||
(!forms || !formIds) && (isFetchingForms || isFetchingFormids); | ||
|
||
if (!isPro) { | ||
return ( | ||
<FormMonitorWrapper> | ||
<EmptyBlock | ||
lite | ||
title={translate( | ||
'Upgrade to the Freeform Pro edition to get access to Form Monitor' | ||
)} | ||
/> | ||
</FormMonitorWrapper> | ||
); | ||
} | ||
|
||
if (isLoading) { | ||
return ( | ||
<FormMonitorWrapper> | ||
<div>{translate('Loading...')}</div> | ||
</FormMonitorWrapper> | ||
); | ||
} | ||
|
||
return ( | ||
<FormMonitorWrapper> | ||
<ul> | ||
{formIds.map((id) => { | ||
const form = forms.find((form) => form.id === id); | ||
if (!form) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<li key={id}> | ||
<Link to={`${id}/tests`}>{form.name}</Link> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</FormMonitorWrapper> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isFetchingFormids
-->isFetchingFormIds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not liking the use of
FM
instead ofFormMonitor
throughout the APIThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good pointers, I'll change them