Skip to content

Commit 8c4df0a

Browse files
committed
setup react-rails
1 parent 7cc6cc9 commit 8c4df0a

30 files changed

+17075
-13
lines changed

.browserslistrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defaults

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ dump.rdb
2828
vendor/data
2929
.vscode/
3030
brakeman_report*.html
31+
32+
/public/packs
33+
/public/packs-test
34+
/node_modules
35+
/yarn-error.log
36+
yarn-debug.log*
37+
.yarn-integrity

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ gem 'text', '~> 1.3', '>= 1.3.1'
6969
gem 'paranoia', '~> 2.4', '>= 2.4.1'
7070
gem 'ancestry', '~> 3.0', '>= 3.0.5'
7171
gem 'write_xlsx', '~> 0.85.7'
72+
gem 'react-rails', '~> 2.6.0'
73+
gem 'webpacker', '~> 4.0.7'
7274

7375
group :development, :test do
7476
gem 'pry'

Gemfile.lock

+14
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ GEM
492492
rack (>= 1.2.0)
493493
rack-protection (1.5.3)
494494
rack
495+
rack-proxy (0.6.5)
496+
rack
495497
rack-test (0.6.3)
496498
rack (>= 1.0)
497499
rails (4.2.2)
@@ -536,6 +538,12 @@ GEM
536538
builder
537539
nokogiri (>= 1.4.1)
538540
trollop
541+
react-rails (2.6.0)
542+
babel-transpiler (>= 0.7.0)
543+
connection_pool
544+
execjs
545+
railties (>= 3.2)
546+
tilt
539547
redis (3.2.2)
540548
representable (3.0.4)
541549
declarative (< 0.1.0)
@@ -692,6 +700,10 @@ GEM
692700
uniform_notifier (1.10.0)
693701
warden (1.2.6)
694702
rack (>= 1.0)
703+
webpacker (4.0.7)
704+
activesupport (>= 4.2)
705+
rack-proxy (>= 0.6.1)
706+
railties (>= 4.2)
695707
websocket-driver (0.7.0)
696708
websocket-extensions (>= 0.1.0)
697709
websocket-extensions (0.1.3)
@@ -781,6 +793,7 @@ DEPENDENCIES
781793
rack-mini-profiler (~> 1.0)
782794
rails (= 4.2.2)
783795
rails-erd
796+
react-rails (~> 2.6.0)
784797
roo (~> 2.2)
785798
rspec-activemodel-mocks
786799
rspec-rails (~> 3.4)
@@ -801,6 +814,7 @@ DEPENDENCIES
801814
tinymce-rails (~> 4.5.6)
802815
typhoeus
803816
uglifier (>= 1.3.0)
817+
webpacker (~> 4.0.7)
804818
whenever (~> 0.9.4)
805819
where-or (~> 0.1.6)
806820
wicked_pdf (~> 1.0, >= 1.0.6)

app/javascript/components/.keep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react'
2+
3+
export default props => {
4+
const { step } = props
5+
6+
return (
7+
step === 1 &&
8+
<div>
9+
<h1>Getting Start</h1>
10+
</div>
11+
)
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React, { useState } from 'react'
2+
import GettingStarted from './gettingStart'
3+
import LivingDetails from './livingDetails'
4+
import OtherDetails from './otherDetails'
5+
import ReferralData from './referralData'
6+
import './styles.scss'
7+
8+
const Forms = props => {
9+
const [step, setStep] = useState(1)
10+
const tabs = [
11+
{text: '1. Getting Started', step: 1},
12+
{text: '2. Living Details', step: 2},
13+
{text: '3. Other Details', step: 3},
14+
{text: '4. Specific Point-of-Referral-Data', step: 4}
15+
]
16+
17+
const activeClass = value => {
18+
return step === value ? 'active' : ''
19+
}
20+
21+
const renderTab = data => {
22+
return (
23+
<span
24+
onClick={() => setStep(data.step)}
25+
className={`tabButton ${activeClass(data.step)}`}
26+
>
27+
{data.text}
28+
</span>
29+
)
30+
}
31+
32+
return (
33+
<div className='container'>
34+
<div className='tabHead'>
35+
{ tabs.map(tab => renderTab(tab)) }
36+
</div>
37+
38+
<GettingStarted step={step} />
39+
<LivingDetails step={step} />
40+
<OtherDetails step={step} />
41+
<ReferralData step={step} />
42+
</div>
43+
)
44+
}
45+
46+
export default Forms
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react'
2+
3+
export default props => {
4+
const { step } = props
5+
6+
return (
7+
step === 2 &&
8+
<div>
9+
<h1>Living Details</h1>
10+
</div>
11+
)
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react'
2+
3+
export default props => {
4+
const { step } = props
5+
6+
return (
7+
step === 3 &&
8+
<div>
9+
<h1>Other Details</h1>
10+
</div>
11+
)
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react'
2+
3+
export default props => {
4+
const { step } = props
5+
6+
return (
7+
step === 4 &&
8+
<div>
9+
<h1>Specifi Points of Refferal Data</h1>
10+
</div>
11+
)
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.container {
2+
width: 100%;
3+
}
4+
5+
.tabHead {
6+
display: flex;
7+
flex: 1;
8+
}
9+
10+
.tabButton {
11+
border-radius: 5px;
12+
color: blue;
13+
flex: 1;
14+
padding: 15px;
15+
margin: 10px;
16+
cursor: pointer;
17+
}
18+
19+
.active {
20+
background: blue;
21+
color: white;
22+
}
23+

app/javascript/packs/application.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint no-console:0 */
2+
// This file is automatically compiled by Webpack, along with any other files
3+
// present in this directory. You're encouraged to place your actual application logic in
4+
// a relevant structure within app/javascript and only use these pack files to reference
5+
// that code so it'll be compiled.
6+
//
7+
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8+
// layout file, like app/views/layouts/application.html.erb
9+
10+
11+
// Uncomment to copy all static images under ../images to the output folder and reference
12+
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
13+
// or the `imagePath` JavaScript helper below.
14+
//
15+
// const images = require.context('../images', true)
16+
// const imagePath = (name) => images(name, true)
17+
18+
console.log('Hello World from Webpacker')
19+
// Support component names relative to this directory:
20+
var componentRequireContext = require.context("components", true);
21+
var ReactRailsUJS = require("react_ujs");
22+
ReactRailsUJS.useContext(componentRequireContext);

app/javascript/packs/hello_react.jsx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Run this example by adding <%= javascript_pack_tag 'hello_react' %> to the head of your layout file,
2+
// like app/views/layouts/application.html.erb. All it does is render <div>Hello React</div> at the bottom
3+
// of the page.
4+
5+
import React from 'react'
6+
import ReactDOM from 'react-dom'
7+
import PropTypes from 'prop-types'
8+
9+
const Hello = props => (
10+
<div>Hello {props.name}!</div>
11+
)
12+
13+
Hello.defaultProps = {
14+
name: 'David'
15+
}
16+
17+
Hello.propTypes = {
18+
name: PropTypes.string
19+
}
20+
21+
document.addEventListener('DOMContentLoaded', () => {
22+
ReactDOM.render(
23+
<Hello name="React" />,
24+
document.body.appendChild(document.createElement('div')),
25+
)
26+
})
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// By default, this pack is loaded for server-side rendering.
2+
// It must expose react_ujs as `ReactRailsUJS` and prepare a require context.
3+
var componentRequireContext = require.context("components", true);
4+
var ReactRailsUJS = require("react_ujs");
5+
ReactRailsUJS.useContext(componentRequireContext);

app/views/clients/new.html.haml

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
- if @referral.present?
1313
= link_to t('.download_supporting_document'), @referral.consent_form.first.url, class: 'btn btn-info btn-sm btn-download', target: :_blank
1414
.ibox-content
15-
= render 'form'
15+
- if current_organization.aht
16+
= react_component('NewClientForm')
17+
- else
18+
= render 'form'

app/views/layouts/application.html.haml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
%title= current_organization.try(:short_name) == 'mho'? "Mother's Heart Organisation" : "OSCaR - Open Source Case-management and Record-keeping"
1111
%script{:src => "https://cdn.jsdelivr.net/npm/[email protected]/dist/interact.min.js"}
12+
= javascript_pack_tag 'application'
1213
= stylesheet_link_tag 'application', media: 'all'
1314
= csrf_meta_tags
1415

babel.config.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
module.exports = function(api) {
2+
var validEnv = ['development', 'test', 'production']
3+
var currentEnv = api.env()
4+
var isDevelopmentEnv = api.env('development')
5+
var isProductionEnv = api.env('production')
6+
var isTestEnv = api.env('test')
7+
8+
if (!validEnv.includes(currentEnv)) {
9+
throw new Error(
10+
'Please specify a valid `NODE_ENV` or ' +
11+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
12+
'"test", and "production". Instead, received: ' +
13+
JSON.stringify(currentEnv) +
14+
'.'
15+
)
16+
}
17+
18+
return {
19+
presets: [
20+
isTestEnv && [
21+
require('@babel/preset-env').default,
22+
{
23+
targets: {
24+
node: 'current'
25+
}
26+
}
27+
],
28+
(isProductionEnv || isDevelopmentEnv) && [
29+
require('@babel/preset-env').default,
30+
{
31+
forceAllTransforms: true,
32+
useBuiltIns: 'entry',
33+
corejs: 3,
34+
modules: false,
35+
exclude: ['transform-typeof-symbol']
36+
}
37+
],
38+
[
39+
require('@babel/preset-react').default,
40+
{
41+
development: isDevelopmentEnv || isTestEnv,
42+
useBuiltIns: true
43+
}
44+
]
45+
].filter(Boolean),
46+
plugins: [
47+
require('babel-plugin-macros'),
48+
require('@babel/plugin-syntax-dynamic-import').default,
49+
isTestEnv && require('babel-plugin-dynamic-import-node'),
50+
require('@babel/plugin-transform-destructuring').default,
51+
[
52+
require('@babel/plugin-proposal-class-properties').default,
53+
{
54+
loose: true
55+
}
56+
],
57+
[
58+
require('@babel/plugin-proposal-object-rest-spread').default,
59+
{
60+
useBuiltIns: true
61+
}
62+
],
63+
[
64+
require('@babel/plugin-transform-runtime').default,
65+
{
66+
helpers: false,
67+
regenerator: true,
68+
corejs: false
69+
}
70+
],
71+
[
72+
require('@babel/plugin-transform-regenerator').default,
73+
{
74+
async: false
75+
}
76+
],
77+
isProductionEnv && [
78+
require('babel-plugin-transform-react-remove-prop-types').default,
79+
{
80+
removeImport: true
81+
}
82+
]
83+
].filter(Boolean)
84+
}
85+
}

bin/webpack

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= "development"
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "rubygems"
11+
require "bundler/setup"
12+
13+
require "webpacker"
14+
require "webpacker/webpack_runner"
15+
16+
APP_ROOT = File.expand_path("..", __dir__)
17+
Dir.chdir(APP_ROOT) do
18+
Webpacker::WebpackRunner.run(ARGV)
19+
end

bin/webpack-dev-server

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= "development"
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "rubygems"
11+
require "bundler/setup"
12+
13+
require "webpacker"
14+
require "webpacker/dev_server_runner"
15+
16+
APP_ROOT = File.expand_path("..", __dir__)
17+
Dir.chdir(APP_ROOT) do
18+
Webpacker::DevServerRunner.run(ARGV)
19+
end

0 commit comments

Comments
 (0)