-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #988 from InseeFr/feat/create-document-from-sims
feat: be able to add document/link from the SIMS page
- Loading branch information
Showing
14 changed files
with
164 additions
and
32 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
5 changes: 5 additions & 0 deletions
5
src/packages/modules-operations/msd/pages/sims-creation/document-form-panel.scss
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,5 @@ | ||
.documents-form-panel { | ||
.container { | ||
width: 100%; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/packages/modules-operations/msd/pages/sims-creation/document-form-panel.tsx
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,54 @@ | ||
import { RightSlidingPanel } from '../../../../components/sliding-panel'; | ||
import { useCodesList } from '../../../../utils/hooks/codeslist'; | ||
import OperationsDocumentationEdition from '../../../document/edition/edition'; | ||
import { useDocumentsStoreContext } from './documents-store-context'; | ||
import './document-form-panel.scss'; | ||
import { useState } from 'react'; | ||
import { Loading } from '../../../../components'; | ||
import { getDocumentsList } from './useDocumentsList'; | ||
|
||
type DocumentFormPanelTypes = { | ||
opened: boolean; | ||
onHide: () => void; | ||
}; | ||
export const DocumentFormPanel = ({ | ||
opened, | ||
onHide, | ||
}: Readonly<DocumentFormPanelTypes>) => { | ||
const langOptions = useCodesList('ISO-639'); | ||
const { lateralPanelOpened, onLateralPanelHide, updateDocumentStores } = | ||
useDocumentsStoreContext(); | ||
const [saving, setSaving] = useState(false); | ||
|
||
const onSave = () => { | ||
setSaving(true); | ||
getDocumentsList() | ||
.then((result) => updateDocumentStores(result)) | ||
.then(() => { | ||
setSaving(false); | ||
if (onLateralPanelHide) { | ||
onLateralPanelHide(); | ||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<RightSlidingPanel | ||
isOpen={opened} | ||
backdropClicked={onHide} | ||
panelClassName="documents-form-panel" | ||
> | ||
{saving ? ( | ||
<Loading textType="saving" /> | ||
) : ( | ||
<OperationsDocumentationEdition | ||
document={{}} | ||
langOptions={langOptions} | ||
type={lateralPanelOpened} | ||
onCancel={onLateralPanelHide} | ||
onSave={onSave} | ||
/> | ||
)} | ||
</RightSlidingPanel> | ||
); | ||
}; |
10 changes: 9 additions & 1 deletion
10
src/packages/modules-operations/msd/pages/sims-creation/documents-store-context.tsx
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
31 changes: 31 additions & 0 deletions
31
src/packages/modules-operations/msd/pages/sims-creation/useDocumentsList.ts
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,31 @@ | ||
import { sortArray } from '../../../../utils/array-utils'; | ||
import { GeneralApi } from '../../../../sdk/general-api'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export const useDocumentsList = () => { | ||
const [documentStores, setDocumentStores] = useState({ | ||
lg1: [], | ||
lg2: [], | ||
}); | ||
|
||
useEffect(() => { | ||
getDocumentsList().then((result: any) => setDocumentStores(result)); | ||
}, []); | ||
|
||
return { documentStores, setDocumentStores }; | ||
}; | ||
|
||
export const getDocumentsList = () => { | ||
return GeneralApi.getDocumentsList().then((results: any) => { | ||
const unSortedDocuments = results.map((document: any) => { | ||
return { | ||
...document, | ||
id: document.uri.substr(document.uri.lastIndexOf('/') + 1), | ||
}; | ||
}); | ||
return { | ||
lg1: sortArray('labelLg1')(unSortedDocuments), | ||
lg2: sortArray('labelLg2')(unSortedDocuments), | ||
}; | ||
}); | ||
}; |
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