Skip to content

Commit

Permalink
Gfay feat use private source (#2)
Browse files Browse the repository at this point in the history
* feat: update open api client

* feat: add comment field

* feat: add authentification by private source

* fix : sonarcloud
  • Loading branch information
MaGOs92 authored Jul 9, 2024
1 parent 42e79c8 commit 825440a
Show file tree
Hide file tree
Showing 33 changed files with 580 additions and 195 deletions.
10 changes: 7 additions & 3 deletions src/api/signalement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ export { OpenAPI } from './core/OpenAPI';
export type { OpenAPIConfig } from './core/OpenAPI';

export type { Author } from './models/Author';
export type { AuthorDTO } from './models/AuthorDTO';
export type { ChangesRequested } from './models/ChangesRequested';
export type { AuthorInput } from './models/AuthorInput';
export type { Client } from './models/Client';
export type { CreateClientDTO } from './models/CreateClientDTO';
export { CreateSignalementDTO } from './models/CreateSignalementDTO';
export { CreateSourceDTO } from './models/CreateSourceDTO';
export type { DeleteNumeroChangesRequestedDTO } from './models/DeleteNumeroChangesRequestedDTO';
export { ExistingLocation } from './models/ExistingLocation';
export { ExistingNumero } from './models/ExistingNumero';
export { ExistingToponyme } from './models/ExistingToponyme';
export { ExistingVoie } from './models/ExistingVoie';
export type { ObjectId } from './models/ObjectId';
export type { NumeroChangesRequestedDTO } from './models/NumeroChangesRequestedDTO';
export type { PaginatedSignalementsDTO } from './models/PaginatedSignalementsDTO';
export type { Point } from './models/Point';
export { Position } from './models/Position';
export type { PositionCoordinatesDTO } from './models/PositionCoordinatesDTO';
export { PositionDTO } from './models/PositionDTO';
export { Signalement } from './models/Signalement';
export { Source } from './models/Source';
export type { ToponymeChangesRequestedDTO } from './models/ToponymeChangesRequestedDTO';
export { UpdateSignalementDTO } from './models/UpdateSignalementDTO';
export type { VoieChangesRequestedDTO } from './models/VoieChangesRequestedDTO';

export { ClientsService } from './services/ClientsService';
export { SignalementsService } from './services/SignalementsService';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type AuthorDTO = {
export type AuthorInput = {
email?: string | null;
captchaToken: string;
};

15 changes: 0 additions & 15 deletions src/api/signalement/models/ChangesRequested.ts

This file was deleted.

10 changes: 5 additions & 5 deletions src/api/signalement/models/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ObjectId } from './ObjectId';
export type Client = {
_id: ObjectId;
_createdAt: number;
_updatedAt: number;
_deletedAt?: number | null;
id: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
nom: string;
processedSignalements?: Array<string> | null;
};

16 changes: 11 additions & 5 deletions src/api/signalement/models/CreateSignalementDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { AuthorDTO } from './AuthorDTO';
import type { ExistingLocation } from './ExistingLocation';
import type { AuthorInput } from './AuthorInput';
import type { DeleteNumeroChangesRequestedDTO } from './DeleteNumeroChangesRequestedDTO';
import type { ExistingNumero } from './ExistingNumero';
import type { ExistingToponyme } from './ExistingToponyme';
import type { ExistingVoie } from './ExistingVoie';
import type { NumeroChangesRequestedDTO } from './NumeroChangesRequestedDTO';
import type { ToponymeChangesRequestedDTO } from './ToponymeChangesRequestedDTO';
import type { VoieChangesRequestedDTO } from './VoieChangesRequestedDTO';
export type CreateSignalementDTO = {
codeCommune: string;
type: CreateSignalementDTO.type;
author?: AuthorDTO | null;
existingLocation?: ExistingLocation | null;
changesRequested: Record<string, any> | null;
author?: AuthorInput | null;
existingLocation?: (ExistingNumero | ExistingVoie | ExistingToponyme) | null;
changesRequested: (NumeroChangesRequestedDTO | DeleteNumeroChangesRequestedDTO | ToponymeChangesRequestedDTO | VoieChangesRequestedDTO) | null;
};
export namespace CreateSignalementDTO {
export enum type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type ObjectId = {
export type DeleteNumeroChangesRequestedDTO = {
comment: string;
};

14 changes: 14 additions & 0 deletions src/api/signalement/models/NumeroChangesRequestedDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { PositionDTO } from './PositionDTO';
export type NumeroChangesRequestedDTO = {
numero: number;
suffixe?: string;
nomVoie: string;
parcelles: Array<string>;
positions: Array<PositionDTO>;
comment?: string | null;
};

3 changes: 1 addition & 2 deletions src/api/signalement/models/PaginatedSignalementsDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { Signalement } from './Signalement';
export type PaginatedSignalementsDTO = {
data: Array<Signalement>;
data: Array<any[]>;
page: number;
limit: number;
total: number;
Expand Down
9 changes: 9 additions & 0 deletions src/api/signalement/models/PositionCoordinatesDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type PositionCoordinatesDTO = {
coordinates: Array<number>;
type: string;
};

23 changes: 23 additions & 0 deletions src/api/signalement/models/PositionDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { PositionCoordinatesDTO } from './PositionCoordinatesDTO';
export type PositionDTO = {
point: PositionCoordinatesDTO;
type: PositionDTO.type;
};
export namespace PositionDTO {
export enum type {
ENTR_E = 'entrée',
B_TIMENT = 'bâtiment',
CAGE_D_ESCALIER = 'cage d’escalier',
LOGEMENT = 'logement',
SERVICE_TECHNIQUE = 'service technique',
D_LIVRANCE_POSTALE = 'délivrance postale',
PARCELLE = 'parcelle',
SEGMENT = 'segment',
INCONNUE = 'inconnue',
}
}

18 changes: 10 additions & 8 deletions src/api/signalement/models/Signalement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
/* tslint:disable */
/* eslint-disable */
import type { Author } from './Author';
import type { ChangesRequested } from './ChangesRequested';
import type { Client } from './Client';
import type { DeleteNumeroChangesRequestedDTO } from './DeleteNumeroChangesRequestedDTO';
import type { ExistingNumero } from './ExistingNumero';
import type { ExistingToponyme } from './ExistingToponyme';
import type { ExistingVoie } from './ExistingVoie';
import type { ObjectId } from './ObjectId';
import type { NumeroChangesRequestedDTO } from './NumeroChangesRequestedDTO';
import type { Source } from './Source';
import type { ToponymeChangesRequestedDTO } from './ToponymeChangesRequestedDTO';
import type { VoieChangesRequestedDTO } from './VoieChangesRequestedDTO';
export type Signalement = {
_id: ObjectId;
_createdAt: number;
_updatedAt: number;
_deletedAt?: number | null;
id: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
codeCommune: string;
type: Signalement.type;
author?: Author | null;
source: Source;
existingLocation?: (ExistingNumero | ExistingVoie | ExistingToponyme) | null;
changesRequested: ChangesRequested;
changesRequested: (NumeroChangesRequestedDTO | DeleteNumeroChangesRequestedDTO | ToponymeChangesRequestedDTO | VoieChangesRequestedDTO);
status?: Signalement.status | null;
source: Source;
processedBy?: Client | null;
};
export namespace Signalement {
Expand Down
10 changes: 5 additions & 5 deletions src/api/signalement/models/Source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ObjectId } from './ObjectId';
export type Source = {
_id: ObjectId;
_createdAt: number;
_updatedAt: number;
_deletedAt?: number | null;
id: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
nom: string;
type: Source.type;
signalements?: Array<string> | null;
};
export namespace Source {
export enum type {
Expand Down
12 changes: 12 additions & 0 deletions src/api/signalement/models/ToponymeChangesRequestedDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { PositionDTO } from './PositionDTO';
export type ToponymeChangesRequestedDTO = {
nom: string;
parcelles: Array<string>;
positions: Array<PositionDTO>;
comment?: string | null;
};

9 changes: 9 additions & 0 deletions src/api/signalement/models/VoieChangesRequestedDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type VoieChangesRequestedDTO = {
nom: string;
comment?: string | null;
};

17 changes: 17 additions & 0 deletions src/api/signalement/services/SourcesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,21 @@ export class SourcesService {
},
});
}
/**
* Get source by token
* @param token
* @returns Source
* @throws ApiError
*/
public static getSourceByToken(
token: string,
): CancelablePromise<Source> {
return __request(OpenAPI, {
method: 'GET',
url: '/sources/token/{token}',
path: {
'token': token,
},
});
}
}
84 changes: 84 additions & 0 deletions src/composants/authentification/AuthentificationModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React, { useContext, useState } from 'react'
import Modal from '../common/Modal'
import styled from 'styled-components'
import SourceContext from '../../contexts/source.context'

const StyledWrapper = styled.form`
.form-control {
display: flex;
justify-content: flex-end;
width: 100%;
margin-top: 20px;
> button:last-of-type {
margin-left: 10px;
}
}
.fr-alert {
margin-top: 20px;
}
`

interface AuthentificationModal {
onClose: () => void
}

export function AuthentificationModal({ onClose }: AuthentificationModal) {
const [token, setToken] = useState('')
const [submitStatus, setSubmitStatus] = useState<string | null>(null)
const { fetchSourceByToken } = useContext(SourceContext)

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault()
setSubmitStatus('loading')
try {
await fetchSourceByToken(token)
setSubmitStatus('success')
onClose()
} catch (error) {
setSubmitStatus('error')
}
}

return (
<Modal title='Connexion' onClose={onClose}>
<StyledWrapper onSubmit={handleSubmit}>
<p>Connectez-vous pour accéder à vos signalements.</p>
<label className='fr-label' htmlFor='nomVoie'>
Renseignez votre jeton d&apos;accès
</label>
<input
className='fr-input'
type='password'
name='token'
required
value={token}
onChange={(event) => setToken(event.target.value)}
/>
{submitStatus === 'success' && (
<div className='fr-alert fr-alert--success'>
<p>Authentification réussie</p>
</div>
)}
{submitStatus === 'error' && (
<div className='fr-alert fr-alert--error'>
<p>Le jeton est incorrect</p>
</div>
)}
<div className='form-control'>
<button className='fr-btn fr-btn--secondary' onClick={onClose} type='button'>
Annuler
</button>
<button
className='fr-btn'
type='submit'
disabled={submitStatus === 'loading' || submitStatus === 'success'}
>
Se connecter
</button>
</div>
</StyledWrapper>
</Modal>
)
}
Loading

0 comments on commit 825440a

Please sign in to comment.