Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
21
Issues
21
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
go
Commits
7600acb2
Commit
7600acb2
authored
Jan 07, 2019
by
David Haynes
🙆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor DebugCreate + Abstract out functionality
- whee reusability
parent
35506d49
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
64 deletions
+79
-64
go/go_ahead/src/Components/Molecules/DebugCreate.jsx
go/go_ahead/src/Components/Molecules/DebugCreate.jsx
+53
-0
go/go_ahead/src/Components/Molecules/index.js
go/go_ahead/src/Components/Molecules/index.js
+2
-1
go/go_ahead/src/Components/Pages/DebugCRUD.jsx
go/go_ahead/src/Components/Pages/DebugCRUD.jsx
+2
-61
go/go_ahead/src/Components/index.js
go/go_ahead/src/Components/index.js
+2
-1
go/go_ahead/src/Utils/GetCSRFToken.js
go/go_ahead/src/Utils/GetCSRFToken.js
+18
-0
go/go_ahead/src/Utils/index.js
go/go_ahead/src/Utils/index.js
+2
-1
No files found.
go/go_ahead/src/Components/Molecules/DebugCreate.jsx
0 → 100644
View file @
7600acb2
import
React
from
"
react
"
;
import
*
as
Yup
from
"
yup
"
;
import
{
Formik
,
Field
,
Form
,
ErrorMessage
}
from
"
formik
"
;
import
{
GetCSRFToken
}
from
"
../../Utils
"
;
const
DebugCreateYup
=
Yup
.
object
().
shape
({
destination
:
Yup
.
string
()
.
url
()
.
max
(
1000
,
"
Too Long!
"
),
short
:
Yup
.
string
()
.
required
(
"
Required
"
)
.
max
(
20
,
"
Too Long!
"
)
// expires: Yup.date()
// .nullable()
// .min(new Date(new Date().getTime() + 24 * 60 * 60 * 1000))
});
const
DebugCreate
=
()
=>
(
<
div
>
<
Formik
initialValues
=
{
{
destination
:
""
,
short
:
""
,
expires
:
null
}
}
validationSchema
=
{
DebugCreateYup
}
onSubmit
=
{
(
values
,
{
setSubmitting
})
=>
{
fetch
(
"
/api/golinks/
"
,
{
method
:
"
post
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
"
X-CSRFToken
"
:
GetCSRFToken
()
},
body
:
JSON
.
stringify
(
values
)
}).
then
(
response
=>
console
.
log
(
response
));
}
}
render
=
{
({
isSubmitting
})
=>
(
<
Form
>
{
"
Destination:
"
}
<
Field
name
=
"destination"
placeholder
=
"https://longwebsitelink.com"
/>
<
ErrorMessage
name
=
"destination"
component
=
"div"
/>
{
"
Short:
"
}
<
Field
name
=
"short"
/>
<
ErrorMessage
name
=
"short"
/>
{
"
Expires:
"
}
<
Field
type
=
"select"
name
=
"expires"
placeholder
=
"leave blank"
/>
<
ErrorMessage
name
=
"expires"
/>
<
button
type
=
"submit"
disabled
=
{
isSubmitting
}
>
Submit
</
button
>
</
Form
>
)
}
/>
</
div
>
);
export
default
DebugCreate
;
go/go_ahead/src/Components/Molecules/index.js
View file @
7600acb2
import
AuthButton
from
"
./AuthButton
"
;
import
DebugRead
from
"
./DebugRead
"
;
import
DebugCreate
from
"
./DebugCreate
"
;
export
{
AuthButton
,
DebugRead
};
export
{
AuthButton
,
DebugRead
,
DebugCreate
};
go/go_ahead/src/Components/Pages/DebugCRUD.jsx
View file @
7600acb2
import
React
from
"
react
"
;
import
{
Formik
,
Field
,
Form
,
ErrorMessage
}
from
"
formik
"
;
import
*
as
Yup
from
"
yup
"
;
import
{
PageTemplate
,
DebugRead
}
from
"
Components
"
;
const
DebugCreate
=
Yup
.
object
().
shape
({
destination
:
Yup
.
string
()
.
url
()
.
max
(
1000
,
"
Too Long!
"
),
short
:
Yup
.
string
()
.
required
(
"
Required
"
)
.
max
(
20
,
"
Too Long!
"
)
// expires: Yup.date()
// .nullable()
// .min(new Date(new Date().getTime() + 24 * 60 * 60 * 1000))
});
import
{
PageTemplate
,
DebugRead
,
DebugCreate
}
from
"
Components
"
;
class
DebugCRUD
extends
React
.
Component
{
constructor
(
props
)
{
...
...
@@ -21,22 +7,6 @@ class DebugCRUD extends React.Component {
this
.
state
=
{};
}
getCookie
(
name
)
{
var
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!=
""
)
{
var
cookies
=
document
.
cookie
.
split
(
"
;
"
);
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
var
cookie
=
cookies
[
i
].
trim
();
// Does this cookie string begin with the name we want?
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
==
name
+
"
=
"
)
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
break
;
}
}
}
return
cookieValue
;
}
render
()
{
return
(
<
PageTemplate
>
...
...
@@ -44,36 +14,7 @@ class DebugCRUD extends React.Component {
<
h1
>
Debug CRUD Page
</
h1
>
<
h3
>
Create
</
h3
>
<
Formik
initialValues
=
{
{
destination
:
""
,
short
:
""
,
expires
:
null
}
}
validationSchema
=
{
DebugCreate
}
onSubmit
=
{
(
values
,
{
setSubmitting
})
=>
{
fetch
(
"
/api/golinks/
"
,
{
method
:
"
post
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
,
"
X-CSRFToken
"
:
this
.
getCookie
(
"
csrftoken
"
)
},
body
:
JSON
.
stringify
(
values
)
}).
then
(
response
=>
console
.
log
(
response
));
}
}
render
=
{
({
isSubmitting
})
=>
(
<
Form
>
<
Field
name
=
"destination"
placeholder
=
"https://longwebsitelink.com"
/>
{
"
"
}
<
ErrorMessage
name
=
"destination"
component
=
"div"
/>
<
Field
name
=
"short"
/>
<
ErrorMessage
name
=
"short"
/>
<
Field
type
=
"select"
name
=
"expires"
/>
<
ErrorMessage
name
=
"expires"
/>
<
button
type
=
"submit"
disabled
=
{
isSubmitting
}
>
Submit
</
button
>
</
Form
>
)
}
/>
<
DebugCreate
/>
<
h3
>
Read
</
h3
>
<
DebugRead
/>
...
...
go/go_ahead/src/Components/index.js
View file @
7600acb2
import
{
AuthButton
,
DebugRead
}
from
"
./Molecules
"
;
import
{
AuthButton
,
DebugRead
,
DebugCreate
}
from
"
./Molecules
"
;
import
{
NavBar
}
from
"
./Organisms
"
;
import
{
HomePage
,
AboutPage
,
DhaynesPage
,
DebugCRUD
}
from
"
./Pages
"
;
import
{
PageTemplate
}
from
"
./Templates
"
;
...
...
@@ -7,6 +7,7 @@ export {
//Molecules
AuthButton
,
DebugRead
,
DebugCreate
,
//Organisms
NavBar
,
//Pages
...
...
go/go_ahead/src/Utils/GetCSRFToken.js
0 → 100644
View file @
7600acb2
const
GetCSRFToken
=
()
=>
{
var
cookieValue
=
null
;
var
name
=
"
csrftoken
"
;
if
(
document
.
cookie
&&
document
.
cookie
!=
""
)
{
var
cookies
=
document
.
cookie
.
split
(
"
;
"
);
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
var
cookie
=
cookies
[
i
].
trim
();
// Does this cookie string begin with the name we want?
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
==
name
+
"
=
"
)
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
break
;
}
}
}
return
cookieValue
;
};
export
default
GetCSRFToken
;
go/go_ahead/src/Utils/index.js
View file @
7600acb2
import
Routes
from
"
./Routes
"
;
import
GetAllGoLinks
from
"
./GetAllGoLinks
"
;
import
GetCSRFToken
from
"
./GetCSRFToken
"
;
export
{
Routes
,
GetAllGoLinks
};
export
{
Routes
,
GetAllGoLinks
,
GetCSRFToken
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment