-
Notifications
You must be signed in to change notification settings - Fork 17
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
Convert React components to functions #581
Open
ilong4rennes
wants to merge
85
commits into
makerspace:main
Choose a base branch
from
ilong4rennes:main
base: main
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.
Open
Changes from 74 commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
e156a9e
refactored Access Token List
a43d922
convert logout component to function
shantinghou 1269bd8
formatting
shantinghou 575f1f0
refactored login class to function
ilong4rennes ea865dc
changed class to function in DateTimeInput.jsx
ilong4rennes 219367f
message form refactor
shantinghou 6c7e402
refactor to use functions
8f9d8b6
refact message form
shantinghou cd936c2
changed class to function in dateperiodinput
ilong4rennes b270c4b
product form refactor
shantinghou a4de00e
refactor admin/src/Membership/MemberAdd.js
f1a7783
make test fix
shantinghou 7335846
refactor MemberBoxGroups
6e46093
request password refactor
shantinghou 1029cea
form input componenets refactored
shantinghou d250307
refactor Member Box Keys
f222d83
refactor group functions other than groupBox
shantinghou adfb807
refactor MemberBoxGroups.js
a91644d
refactor Group Box Permissions
3ac3fc6
refactor Member Box New Message
9816428
Refactor MemberBoxOrders.js
26919cf
Refactor MemberBoxPermissions
88be7a0
remove unnecessary dependency in refactor
c497477
modernize legacy api with use of contexts
shantinghou 9eb0ced
refactor KeyEdit
b985bc8
refactor MemberBox and associated children components
fa772c5
changed class to function in app.jsx
ilong4rennes 6da2498
changed class to function in checkboxinput
ilong4rennes f09cf23
changed class to function in memberform
ilong4rennes 93e2275
changed GroupForm.js
ilong4rennes 0390540
changed class to function in fileinput
ilong4rennes 0696837
changed class to function in countrydropdown
ilong4rennes 3935f2d
changed class to function in categoryperiodsinput
ilong4rennes f90483d
changed class to function in keyhandoutform.jsx
ilong4rennes 00ba257
changed class to functions in CollectionTable.js
ilong4rennes a6616aa
Merge pull request #1 from ilong4rennes/feature/refactorAccessTokenList
shantinghou ddfb7f9
Merge pull request #2 from ilong4rennes/refactor-logout
shantinghou e556caa
Merge pull request #3 from ilong4rennes/refactor/login
shantinghou ca3aef8
Merge pull request #4 from ilong4rennes/refactor-messageForm
shantinghou a572a66
Merge pull request #5 from ilong4rennes/password-reset
shantinghou f502ce6
Merge pull request #6 from ilong4rennes/refactor-input-componenets
shantinghou b7404c0
Merge pull request #7 from ilong4rennes/refactor-group
shantinghou 9435fa9
Merge pull request #8 from ilong4rennes/refactor/component-files
shantinghou 2ab7b07
Merge pull request #10 from ilong4rennes/refactor/component-files-2
shantinghou ea2f1a3
Merge pull request #11 from ilong4rennes/features/refactorMemberBoxRe…
shantinghou 74da2c2
Merge pull request #12 from ilong4rennes/features/keyedit
shantinghou 76f3e64
Merge pull request #13 from ilong4rennes/features/refactorMemberBoxOr…
shantinghou 4aa8942
Merge pull request #14 from ilong4rennes/features/refactorMemberBoxPe…
shantinghou f0adae3
Merge pull request #15 from ilong4rennes/features/refactorMemberBoxNe…
shantinghou 3611163
Merge pull request #16 from ilong4rennes/features/GroupBoxPermissions
shantinghou 7b488aa
Merge pull request #18 from ilong4rennes/features/refactorMemberBoxKeys
shantinghou 2c8d057
Merge pull request #19 from ilong4rennes/features/refactorMemberAdd
shantinghou 275cd34
lint error fix
shantinghou 0d57538
Merge pull request #17 from ilong4rennes/features/refactorMemberBoxGr…
shantinghou 9b4ece6
fix membership group lint
shantinghou 9836d0a
Merge pull request #20 from ilong4rennes/membership-group-fix
shantinghou ea94660
fix get error
ilong4rennes 4e7aa3e
Merge pull request #21 from ilong4rennes/fix-memberboxgroup
ilong4rennes 760ac77
changed class to function in servicetokenlist
ilong4rennes 4d19245
changed productEdit
ilong4rennes 806563c
changed productadd
ilong4rennes fdedf23
changed sales
ilong4rennes 0c716bb
refactored messages
ilong4rennes ce56943
refactored membership
ilong4rennes 6ed27d1
update accounting product
ilong4rennes e5ad72f
Merge pull request #29 from ilong4rennes/refactor-membership
ilong4rennes fd7ef5f
Merge pull request #28 from ilong4rennes/refactor-messages
ilong4rennes d2455a3
Merge pull request #27 from ilong4rennes/refactor-sales
ilong4rennes a06154c
Merge pull request #25 from ilong4rennes/refactor-file47
ilong4rennes 6e80562
Merge pull request #24 from ilong4rennes/refactor-file48
ilong4rennes b1af1d7
Merge pull request #23 from ilong4rennes/refactor-file49
ilong4rennes 4604cd1
Merge pull request #30 from ilong4rennes/refactor/component-files
ilong4rennes 112ec5c
fix span error
ilong4rennes eaccc32
Merge pull request #31 from ilong4rennes/refactor/fix-membership
ilong4rennes a5b9cfb
fix gift card network error
shantinghou ce5f2b0
fix order show
shantinghou 6b3976a
Merge pull request #32 from ilong4rennes/fix-gift-card-show
shantinghou 7df1644
fix messages
ilong4rennes 850746e
fix span show
ilong4rennes 98fca29
Merge pull request #34 from ilong4rennes/refactor/span-info
ilong4rennes d69424c
Merge pull request #33 from ilong4rennes/refactor/email-log
ilong4rennes c58b7a8
refactored the 'preventDefault' error, and removed comments
ilong4rennes ef57643
Remove useCallback
ilong4rennes 577b374
Remove useCallback
ilong4rennes f82d9d8
Merge pull request #35 from ilong4rennes/refactor/fix-prevent-default
ilong4rennes 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,65 @@ | ||
import React from "react"; | ||
import React, { useEffect, useState } from "react"; | ||
import DatePeriod from "../Models/DatePeriod"; | ||
import { utcToday } from "../utils"; | ||
import DatePeriodInput from "./DatePeriodInput"; | ||
import DatePeriod from "../Models/DatePeriod"; | ||
|
||
export default class CategoryPeriodsInput extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { periods: [] }; | ||
} | ||
const CategoryPeriodsInput = ({ categoryPeriods, showHistoric }) => { | ||
const [periods, setPeriods] = useState([]); | ||
|
||
componentDidMount() { | ||
const { categoryPeriods } = this.props; | ||
categoryPeriods.subscribe(() => { | ||
this.setState({ periods: categoryPeriods.periods }); | ||
useEffect(() => { | ||
const unsubscribe = categoryPeriods.subscribe(() => { | ||
setPeriods(categoryPeriods.periods); | ||
}); | ||
} | ||
|
||
render() { | ||
const { category } = this.props.categoryPeriods; | ||
const { showHistoric } = this.props; | ||
const { periods } = this.state; | ||
|
||
const today = utcToday(); | ||
const categoryTitle = { | ||
labaccess: "Labaccess", | ||
special_labaccess: "Access till lokalen (styrelsen etc)", | ||
membership: "Medlemsskap", | ||
return () => { | ||
unsubscribe(); | ||
}; | ||
}, [categoryPeriods]); | ||
|
||
const { category } = categoryPeriods; | ||
|
||
const today = utcToday(); | ||
const categoryTitle = { | ||
labaccess: "Labaccess", | ||
special_labaccess: "Access till lokalen (styrelsen etc)", | ||
membership: "Medlemsskap", | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h4 className="uk-margin-top">{categoryTitle[category]}</h4> | ||
{periods.map((p) => { | ||
if (!showHistoric && p.end < today) { | ||
return null; | ||
} | ||
return ( | ||
<div key={p.id}> | ||
<DatePeriodInput period={p} /> | ||
| ||
<a | ||
onClick={() => categoryPeriods.remove(p)} | ||
className="removebutton" | ||
> | ||
<i className="uk-icon-trash" /> | ||
</a> | ||
</div> | ||
); | ||
})} | ||
<button | ||
type="button" | ||
style={{ marginTop: "2px" }} | ||
className="uk-button uk-button-small uk-button-success" | ||
onClick={() => { | ||
const period = new DatePeriod(); | ||
period.start = utcToday(); | ||
period.end = utcToday(); | ||
categoryPeriods.add(period); | ||
}} | ||
> | ||
Lägg till period | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h4 className="uk-margin-top">{categoryTitle[category]}</h4> | ||
{periods.map((p) => { | ||
if (!showHistoric && p.end < today) { | ||
return null; | ||
} | ||
return ( | ||
<div key={p.id}> | ||
<DatePeriodInput key={p.id} period={p} /> | ||
| ||
<a | ||
onClick={() => | ||
this.props.categoryPeriods.remove(p) | ||
} | ||
className="removebutton" | ||
> | ||
<i className="uk-icon-trash" /> | ||
</a> | ||
</div> | ||
); | ||
})} | ||
<button | ||
type="button" | ||
style={{ marginTop: "2px" }} | ||
className="uk-button uk-button-small uk-button-success" | ||
onClick={() => { | ||
const period = new DatePeriod(); | ||
period.start = utcToday(); | ||
period.end = utcToday(); | ||
this.props.categoryPeriods.add(period); | ||
}} | ||
> | ||
Lägg till period | ||
</button> | ||
</div> | ||
); | ||
} | ||
} | ||
export default CategoryPeriodsInput; |
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 |
---|---|---|
@@ -1,76 +1,76 @@ | ||
import React from "react"; | ||
import classNames from "classnames/bind"; | ||
import React, { useEffect, useState } from "react"; | ||
|
||
export default class CheckboxInput extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
value: false, | ||
selected: false, | ||
isDirty: false, | ||
}; | ||
} | ||
const CheckboxInput = ({ | ||
model, | ||
name, | ||
title, | ||
icon, | ||
disabled, | ||
formrow, | ||
tabIndex, | ||
label, | ||
}) => { | ||
const [value, setValue] = useState(false); | ||
const [isDirty, setIsDirty] = useState(false); | ||
|
||
componentDidMount() { | ||
const { model, name } = this.props; | ||
this.unsubscribe = model.subscribe(() => | ||
this.setState({ | ||
value: model[name] === "" ? false : model[name], | ||
isDirty: model.isDirty(name), | ||
}), | ||
); | ||
} | ||
useEffect(() => { | ||
const unsubscribe = model.subscribe(() => { | ||
setValue(model[name] === "" ? false : model[name]); | ||
setIsDirty(model.isDirty(name)); | ||
}); | ||
|
||
componentWillUnmount() { | ||
this.unsubscribe(); | ||
} | ||
return () => { | ||
unsubscribe(); | ||
}; | ||
}, [model, name]); | ||
|
||
render() { | ||
const { value, isDirty } = this.state; | ||
const { model, name, title, icon, disabled, formrow, tabIndex, label } = | ||
this.props; | ||
const classes = classNames(name, { | ||
"uk-form-row": formrow, | ||
changed: isDirty, | ||
}); | ||
|
||
const classes = classNames(name, { | ||
"uk-form-row": formrow, | ||
changed: isDirty, | ||
}); | ||
const handleChange = () => { | ||
model[name] = !model[name]; | ||
}; | ||
|
||
const input = ( | ||
<input | ||
id={name} | ||
name={name} | ||
className="" | ||
checked={value} | ||
disabled={disabled} | ||
type="checkbox" | ||
tabIndex={tabIndex} | ||
onChange={() => (model[name] = !model[name])} | ||
/> | ||
); | ||
const input = ( | ||
<input | ||
id={name} | ||
name={name} | ||
className="" | ||
checked={value} | ||
disabled={disabled} | ||
type="checkbox" | ||
tabIndex={tabIndex} | ||
onChange={handleChange} | ||
/> | ||
); | ||
|
||
return ( | ||
<div className={classes}> | ||
{label ? ( | ||
<label className="uk-form-label" htmlFor={name}> | ||
{title} | ||
</label> | ||
) : null} | ||
<div className="uk-form-controls"> | ||
{icon ? ( | ||
<div className="uk-form-icon"> | ||
<i className={"uk-icon-" + icon} /> | ||
{input} | ||
</div> | ||
) : ( | ||
input | ||
)} | ||
</div> | ||
return ( | ||
<div className={classes}> | ||
{label && ( | ||
<label className="uk-form-label" htmlFor={name}> | ||
{title} | ||
</label> | ||
)} | ||
<div className="uk-form-controls"> | ||
{icon ? ( | ||
<div className="uk-form-icon"> | ||
<i className={"uk-icon-" + icon} /> | ||
{input} | ||
</div> | ||
) : ( | ||
input | ||
)} | ||
</div> | ||
); | ||
} | ||
} | ||
</div> | ||
); | ||
}; | ||
|
||
CheckboxInput.defaultProps = { | ||
formrow: true, | ||
label: true, | ||
}; | ||
|
||
export default CheckboxInput; |
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.
🛠️ Refactor suggestion
Optimize model subscription updates
The subscription callback should use functional updates to ensure state updates are based on the latest values.
📝 Committable suggestion