on master help sign in
login: wip trying to fix validation
commit09c909e168b646c648891d325b57a9125c6b8b95 authorHunter Miller <hunter@hmiller.dev> dateThu 3 Mar 2022, 17:51 (5 years ago) parent8eb3253
5 files changed+39−2
src/components/L2/Headers/AdvancedOptions.tsx+17 src/form/SubmitButton.js+12 src/form/validators.js+1 src/views/Login/Ticket.tsx+5−1 src/views/Points.tsx+4−1
src/components/L2/Headers/AdvancedOptions.tsx+17
@@ -1,6 +1,7 @@
11import React, { useState } from 'react';
22import { Text, Box, Checkbox, Icon, Row } from '@tlon/indigo-react';
33import './AdvancedOptions.scss';
4+import styled from 'styled-components';
45
56interface AdvancedOptionsProps {
67 options: {
@@ -11,6 +12,15 @@ interface AdvancedOptionsProps {
1112 }[];
1213}
1314
15+// Hide this input completely
16+const HiddenInput = styled.input`
17+ position: absolute;
18+ opacity: 0;
19+ height: 0;
20+ width: 0;
21+ margin: 0px;
22+`;
23+
1424export default function AdvancedOptions({ options }: AdvancedOptionsProps) {
1525 const showingAny = options.reduce(
1626 (anySelected, { selected }) => anySelected || selected,
@@ -33,6 +43,13 @@ export default function AdvancedOptions({ options }: AdvancedOptionsProps) {
3343 <Box className="options">
3444 {options.map((option, ind) => (
3545 <Row className="option" key={`adv-opt-${ind}`}>
46+ <HiddenInput
47+ checked={option.selected}
48+ name={option.key}
49+ id={option.key}
50+ type="checkbox"
51+ readOnly
52+ />
3653 <Checkbox
3754 className={`checkbox ${option.selected ? 'checked' : ''}`}
3855 {...option}
src/form/SubmitButton.js+12
@@ -15,6 +15,8 @@ export default function SubmitButton({
1515 ...rest
1616}) {
1717 const {
18+ values,
19+ errors,
1820 valid,
1921 validating,
2022 submitting,
@@ -25,6 +27,16 @@ export default function SubmitButton({
2527 submitSucceeded,
2628 } = useFormState();
2729
30+ console.log({
31+ values,
32+ valid,
33+ validating,
34+ submitting,
35+ hasValidationErrors,
36+ errors,
37+ submitErrors,
38+ });
39+
2840 const onlyWarningInSubmitErrors = onlyHasWarning(submitErrors);
2941
3042 // can submit if:
src/form/validators.js+1
@@ -168,6 +168,7 @@ export const composeValidator = (
168168 // that means our `validating` state flickers the UI and it looks pretty bad.
169169 // The solution is to conditionally return a promise only when necessary.
170170 return values => {
171+ debugger;
171172 // ask for field-level errors
172173 const errorsOrPromise = fieldLevelValidator(values);
173174
src/views/Login/Ticket.tsx+5−1
@@ -61,7 +61,10 @@ export default function Ticket({ className, goHome }: TicketProps) {
6161 }
6262
6363 if (values.useShards) {
64+ errors.ticket = undefined;
65+
6466 if (errors.shard1 || errors.shard2 || errors.shard3) {
67+ console.log(errors);
6568 return errors;
6669 }
6770 const empty = ['shard1', 'shard2', 'shard3'].filter(s => !values[s]);
@@ -70,6 +73,7 @@ export default function Ticket({ className, goHome }: TicketProps) {
7073 empty.forEach(s => {
7174 errors[s] = 'Please provide at least two out of three shards.';
7275 });
76+ console.log(errors);
7377 return errors;
7478 }
7579 } else {
@@ -153,7 +157,7 @@ export default function Ticket({ className, goHome }: TicketProps) {
153157 const initialValues = useMemo(
154158 () => ({
155159 point: impliedPoint || '',
156− usePasshrase: false,
160+ usePassphrase: false,
157161 useShards: false,
158162 ticketHidden: true,
159163 useAdvanced: false,
src/views/Points.tsx+4−1
@@ -133,6 +133,8 @@ export default function Points() {
133133 [pointList, rejectedPoints]
134134 );
135135
136+ console.log(allPoints, pointList);
137+
136138 // if we can only interact with a single point, jump to the point page.
137139 // if there are any pending transfers, incoming or outgoing, stay on this
138140 // page, because those can only be completed/cancelled here.
@@ -175,7 +177,8 @@ export default function Points() {
175177
176178 // If the user has any stars or galaxies, give a polite heads up that
177179 // it can take some time for the roller be aware of L1 TXs
178− const showMigrateNotice = !displayEmptyState &&
180+ const showMigrateNotice =
181+ !displayEmptyState &&
179182 allPoints.some(p => isStar(p.value) || isGalaxy(p.value));
180183
181184 const starReleasing = starReleaseDetails