fix organisation
This commit is contained in:
parent
c76f908d5c
commit
2da0f0210d
@ -71,8 +71,20 @@ export class AuthService {
|
|||||||
// 3. Otherwise, use default organization
|
// 3. Otherwise, use default organization
|
||||||
const finalOrganizationId = await this.resolveOrganizationId(organizationId, organizationData);
|
const finalOrganizationId = await this.resolveOrganizationId(organizationId, organizationData);
|
||||||
|
|
||||||
// Determine role: use invitation role if provided, otherwise default to USER
|
// Determine role:
|
||||||
const userRole = invitationRole ? (invitationRole as UserRole) : UserRole.USER;
|
// - If invitation role is provided (invited user), use it
|
||||||
|
// - If organizationData is provided (new organization creator), make them MANAGER
|
||||||
|
// - Otherwise, default to USER
|
||||||
|
let userRole: UserRole;
|
||||||
|
if (invitationRole) {
|
||||||
|
userRole = invitationRole as UserRole;
|
||||||
|
} else if (organizationData) {
|
||||||
|
// User creating a new organization becomes MANAGER
|
||||||
|
userRole = UserRole.MANAGER;
|
||||||
|
} else {
|
||||||
|
// Default to USER for other cases
|
||||||
|
userRole = UserRole.USER;
|
||||||
|
}
|
||||||
|
|
||||||
const user = User.create({
|
const user = User.create({
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
|
|||||||
@ -39,6 +39,9 @@ export default function OrganizationSettingsPage() {
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// Check if user can edit organization (only ADMIN and MANAGER)
|
||||||
|
const canEdit = user?.role === 'ADMIN' || user?.role === 'MANAGER';
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user?.organizationId) {
|
if (user?.organizationId) {
|
||||||
loadOrganization();
|
loadOrganization();
|
||||||
@ -179,6 +182,18 @@ export default function OrganizationSettingsPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Read-only warning for USER role */}
|
||||||
|
{!canEdit && (
|
||||||
|
<div className="mb-6 bg-blue-50 border border-blue-200 rounded-lg p-4">
|
||||||
|
<div className="flex items-center">
|
||||||
|
<svg className="w-5 h-5 text-blue-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<p className="text-blue-800 font-medium">Mode lecture seule - Seuls les administrateurs et managers peuvent modifier l'organisation</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Tabs */}
|
{/* Tabs */}
|
||||||
<div className="bg-white rounded-lg shadow-md">
|
<div className="bg-white rounded-lg shadow-md">
|
||||||
<div className="border-b border-gray-200">
|
<div className="border-b border-gray-200">
|
||||||
@ -230,7 +245,8 @@ export default function OrganizationSettingsPage() {
|
|||||||
type="text"
|
type="text"
|
||||||
value={formData.name}
|
value={formData.name}
|
||||||
onChange={e => handleChange('name', e.target.value)}
|
onChange={e => handleChange('name', e.target.value)}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
disabled={!canEdit}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed"
|
||||||
placeholder="Xpeditis"
|
placeholder="Xpeditis"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
@ -246,7 +262,8 @@ export default function OrganizationSettingsPage() {
|
|||||||
type="text"
|
type="text"
|
||||||
value={formData.siren}
|
value={formData.siren}
|
||||||
onChange={e => handleChange('siren', e.target.value.replace(/\D/g, '').slice(0, 9))}
|
onChange={e => handleChange('siren', e.target.value.replace(/\D/g, '').slice(0, 9))}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
disabled={!canEdit}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed"
|
||||||
placeholder="123 456 789"
|
placeholder="123 456 789"
|
||||||
maxLength={9}
|
maxLength={9}
|
||||||
/>
|
/>
|
||||||
@ -263,7 +280,8 @@ export default function OrganizationSettingsPage() {
|
|||||||
type="text"
|
type="text"
|
||||||
value={formData.eori}
|
value={formData.eori}
|
||||||
onChange={e => handleChange('eori', e.target.value.toUpperCase())}
|
onChange={e => handleChange('eori', e.target.value.toUpperCase())}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
disabled={!canEdit}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed"
|
||||||
placeholder="FR123456789"
|
placeholder="FR123456789"
|
||||||
maxLength={17}
|
maxLength={17}
|
||||||
/>
|
/>
|
||||||
@ -277,7 +295,8 @@ export default function OrganizationSettingsPage() {
|
|||||||
type="tel"
|
type="tel"
|
||||||
value={formData.contact_phone}
|
value={formData.contact_phone}
|
||||||
onChange={e => handleChange('contact_phone', e.target.value)}
|
onChange={e => handleChange('contact_phone', e.target.value)}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
disabled={!canEdit}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed"
|
||||||
placeholder="+33 6 80 18 28 12"
|
placeholder="+33 6 80 18 28 12"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -289,7 +308,8 @@ export default function OrganizationSettingsPage() {
|
|||||||
type="email"
|
type="email"
|
||||||
value={formData.contact_email}
|
value={formData.contact_email}
|
||||||
onChange={e => handleChange('contact_email', e.target.value)}
|
onChange={e => handleChange('contact_email', e.target.value)}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
disabled={!canEdit}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed"
|
||||||
placeholder="contact@xpeditis.com"
|
placeholder="contact@xpeditis.com"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -307,7 +327,8 @@ export default function OrganizationSettingsPage() {
|
|||||||
type="text"
|
type="text"
|
||||||
value={formData.address_street}
|
value={formData.address_street}
|
||||||
onChange={e => handleChange('address_street', e.target.value)}
|
onChange={e => handleChange('address_street', e.target.value)}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
disabled={!canEdit}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed"
|
||||||
placeholder="123 Rue de la Paix"
|
placeholder="123 Rue de la Paix"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
@ -323,7 +344,8 @@ export default function OrganizationSettingsPage() {
|
|||||||
type="text"
|
type="text"
|
||||||
value={formData.address_postal_code}
|
value={formData.address_postal_code}
|
||||||
onChange={e => handleChange('address_postal_code', e.target.value)}
|
onChange={e => handleChange('address_postal_code', e.target.value)}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
disabled={!canEdit}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed"
|
||||||
placeholder="75001"
|
placeholder="75001"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
@ -336,7 +358,8 @@ export default function OrganizationSettingsPage() {
|
|||||||
type="text"
|
type="text"
|
||||||
value={formData.address_city}
|
value={formData.address_city}
|
||||||
onChange={e => handleChange('address_city', e.target.value)}
|
onChange={e => handleChange('address_city', e.target.value)}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
disabled={!canEdit}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed"
|
||||||
placeholder="Paris"
|
placeholder="Paris"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
@ -351,7 +374,8 @@ export default function OrganizationSettingsPage() {
|
|||||||
<select
|
<select
|
||||||
value={formData.address_country}
|
value={formData.address_country}
|
||||||
onChange={e => handleChange('address_country', e.target.value)}
|
onChange={e => handleChange('address_country', e.target.value)}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
disabled={!canEdit}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed"
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
<option value="FR">France</option>
|
<option value="FR">France</option>
|
||||||
@ -370,31 +394,33 @@ export default function OrganizationSettingsPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Actions */}
|
{/* Actions */}
|
||||||
<div className="bg-gray-50 px-8 py-4 border-t border-gray-200 flex items-center justify-end space-x-4">
|
{canEdit && (
|
||||||
<button
|
<div className="bg-gray-50 px-8 py-4 border-t border-gray-200 flex items-center justify-end space-x-4">
|
||||||
type="button"
|
<button
|
||||||
onClick={handleCancel}
|
type="button"
|
||||||
disabled={isSaving}
|
onClick={handleCancel}
|
||||||
className="px-6 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
disabled={isSaving}
|
||||||
>
|
className="px-6 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
||||||
Annuler
|
>
|
||||||
</button>
|
Annuler
|
||||||
<button
|
</button>
|
||||||
type="button"
|
<button
|
||||||
onClick={handleSave}
|
type="button"
|
||||||
disabled={isSaving || !formData.name || !formData.address_street}
|
onClick={handleSave}
|
||||||
className="px-6 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center"
|
disabled={isSaving || !formData.name || !formData.address_street}
|
||||||
>
|
className="px-6 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center"
|
||||||
{isSaving ? (
|
>
|
||||||
<>
|
{isSaving ? (
|
||||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
<>
|
||||||
Enregistrement...
|
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
||||||
</>
|
Enregistrement...
|
||||||
) : (
|
</>
|
||||||
'Enregistrer'
|
) : (
|
||||||
)}
|
'Enregistrer'
|
||||||
</button>
|
)}
|
||||||
</div>
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user