-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cms] feat: switch proposal token to proposal name on invoice lineitem (
- Loading branch information
1 parent
49883cf
commit ca866ff
Showing
21 changed files
with
323 additions
and
75 deletions.
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
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
62 changes: 62 additions & 0 deletions
62
src/components/InvoiceDatasheet/components/LazySelector.jsx
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 @@ | ||
import React, { useState, useCallback, useMemo, useEffect } from "react"; | ||
import { Select, Spinner } from "pi-ui"; | ||
|
||
const fetchingOption = { | ||
isFetchingOption: true, | ||
label: "Fetch more...", | ||
value: "" | ||
}; | ||
|
||
const LazySelector = ({ | ||
options, | ||
onFetch, | ||
needsFetch, | ||
onChange, | ||
onCommit, | ||
error = null | ||
}) => { | ||
const [selected, setSelected] = useState(); | ||
const [loading, setLoading] = useState(false); | ||
const getValueObj = useCallback( | ||
(value) => options.find((op) => op.value === value), | ||
[options] | ||
); | ||
|
||
const handleChange = useCallback( | ||
({ isFetchingOption = false, value }) => { | ||
if (isFetchingOption) { | ||
setLoading(true); | ||
onFetch(); | ||
} else { | ||
setSelected(getValueObj(value)); | ||
onChange(value); | ||
onCommit(value); | ||
} | ||
}, | ||
[onFetch, setSelected, onChange, onCommit, getValueObj] | ||
); | ||
|
||
const ops = useMemo( | ||
() => (needsFetch ? [...options, fetchingOption] : options), | ||
[options, needsFetch] | ||
); | ||
|
||
useEffect( | ||
function onOptionsChangeOrError() { | ||
return () => { | ||
setLoading(false); | ||
}; | ||
}, | ||
[options, error] | ||
); | ||
|
||
return loading ? ( | ||
<div className="margin-top-s"> | ||
<Spinner invert /> | ||
</div> | ||
) : ( | ||
<Select options={ops} value={selected} onChange={handleChange} /> | ||
); | ||
}; | ||
|
||
export default LazySelector; |
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.